?
Solved

How do I fill a dBase IV numeric field with a number without getting decimal points in the file?

Posted on 2008-06-10
1
Medium Priority
?
1,368 Views
Last Modified: 2013-11-24
I try to create a dbf file (dBase 4) from C# using an OleDb connection as shown in code snippet.
When I run it the file is created but the number field is written with 5 decimal points.
How do I get rid of the decimal points in the file?
I've tried replacing the number with a variable of different types (int, decimal, string with no decimal formatting etc.) but nothing works.
public string CreateDbfFile()
{
    OleDbConnection oleDbConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\TEMP\\DBF;Extended Properties=dBASE IV;");
 
    try
    {
        oleDbConn.Open();
 
        OleDbCommand cmd = new OleDbCommand();
        cmd.CommandText = "CREATE table Test2 (Name CHAR(50), myNum NUMBER);";
        cmd.Connection = oleDbConn;
        cmd.ExecuteNonQuery();
 
        cmd = new OleDbCommand();
        cmd.Connection = oleDbConn;
        cmd.CommandText = "INSERT INTO Test2 VALUES('John Smith', 1234567890);";
        cmd.ExecuteNonQuery();
    }
    catch (Exception ex)
    {
        return ex.Message;
    }
    finally
    {
        oleDbConn.Close();
    }
 
    return "Wohoo";
}

Open in new window

0
Comment
Question by:ekberglinda
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
ekberglinda earned 0 total points
ID: 21768087
"Solved" it by creating a template in Excel (where number of decimal points can be set) which I then update with info.
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question