Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1386
  • Last Modified:

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

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
ekberglinda
Asked:
ekberglinda
1 Solution
 
ekberglindaAuthor Commented:
"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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now