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
1,363 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

726 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