Recently I have to develop quick report based on legacy data from .DBF file.
There was no much time, so I decided to do that in c# using ODBC.net data provider. This post shows one way of loading DBF table in DataTable object.
System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection();
//short connection string ( but works )
conn.ConnectionString = @"DSN=dBase Files";
conn.Open();
System.Data.Odbc.OdbcCommand comm = new System.Data.Odbc.OdbcCommand();
comm.CommandText = "SELECT * FROM c:\\folder\\fileName.dbf" ;
comm.Connection = conn;
DataTable dt = new DataTable();
dt.Load(comm.ExecuteReader());
conn.Close();
//after this you cab do what you want with the data table
Tuesday, March 30, 2010
Subscribe to:
Post Comments (Atom)
It is giving error my dear ...
ReplyDeleteplease FYI below: I am getting the error
ERROR [HY000] [Microsoft][ODBC dBASE Driver] External table is not in the expected format.