• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 323
  • Last Modified:

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

      oConn.Open();
      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++)
            {
                  ...
            }
      }


Thanks
0
greg_roberts
Asked:
greg_roberts
  • 2
  • 2
1 Solution
 
MikeGTCommented:
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;");

            dbConn.Open();
            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++){
                Console.WriteLine(t.Rows[i]["TABLE_NAME"].ToString());
            }
            dbConn.Close();
0
 
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 ..

Thanks
0
 
MikeGTCommented:
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?
0
 
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
http://www1.arcwebservices.com/v2006/help/awsite/properties.dbf

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.
Thanks
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now