ODbc .NET DBF Access - Want to read Headers

>> 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++)

Who is Participating?
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?
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++){
greg_robertsAuthor Commented:
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 ..

greg_robertsAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.