ODbc .NET DBF Access - Want to read Headers

Posted on 2007-07-29
Last Modified: 2013-11-24
>> I want to tnow if it is possible to read the column header names using Odbc for DBF files ?

Currently the field count is returned OK but no fields are set at startup.
Reading row records works a treat.
e.g. C# code
      string conn = @"Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=" + dir + ";";

      oConn = new OdbcConnection(conn);
    oCmd = new OdbcCommand("select * from " + lFile.Name);

      oCmd.Connection = oConn;

    oRd = oCmd.ExecuteReader();
    // At this point the field count is correct but NO fields are set
  // Can see no header names in the class  
      while (oRd.Read())
            // At this point row data is being returned
            for (int i=0; i < oRd.FieldCount; i++)

Question by:greg_roberts
    LVL 5

    Expert Comment

    I think you are going to need to use OLEDB to do this as such

     OleDbConnection dbConn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;" +
                                                                @"Data Source=c:\temp;" +
                                                                @"Extended Properties=DBASE III;");

                System.Data.DataTable t = dbConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[]{null, null, null, "TABLE"});
                for(int i=0; i < t.Rows.Count; i++){

    Author Comment

    Looks promising, how is the path to the specific myfile.dbf covered ?

    I tried this and got exceptions from OLE. The trick is the connection string
    or open that targets the specific DBF fiel i am interested in ..

    LVL 5

    Accepted Solution

    as far as I am aware, DBF files are single tables, so the path specified is the "database" and the .dbf files are the tables in the database. I have tested this, the code above was an actual .dbf file, maybe the dbf format you have is not DBase III compatable?

    Author Comment

    We must be talking about different things.

    I was talking about a single DBF file which can be opened and the header row read as well as the other rows. I can read the other rows but not the header.

    I found a dbf file on the internet

    In this example i was after the NAME, STREET, ....   info .
    I can't see how the connection string above can possibly know which DBF file you wanted to look at.
    I am going to award the points anyway for your time but i don't consider the problem solved.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
    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 …

    737 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

    20 Experts available now in Live!

    Get 1:1 Help Now