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,341 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
Comment Utility
"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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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 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 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 …

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now