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,355 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
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

839 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