reading dbase file without standard .dbf extension.

Posted by Nathan W on Stack Overflow See other posts from Stack Overflow or by Nathan W
Published on 2009-05-16T08:47:18Z Indexed on 2010/06/01 14:03 UTC
Read the original article Hit count: 385

Filed under:
|
|

I am trying to read a file which is just a dbase file but without the standard extension the file is something like:

Test.Dat

I am using this block of code to try and read the file:

string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Temp;Extended Properties=dBase III";
            OleDbConnection dBaseConnection = new OleDbConnection(ConnectionString);
            dBaseConnection.Open();

            OleDbDataAdapter oDataAdapter = new OleDbDataAdapter("SELECT * FROM Test", ConnectionString);
            DataSet oDataSet = new DataSet();
            oDataAdapter.Fill(oDataSet);//I get the error right here...
            DataTable oDataTable = oDataSet.Tables[0];
            foreach (DataRow dr in oDataTable.Rows)
            {
                Console.WriteLine(dr["Name"]);
            }

Of course this crashes because it can't find the dbase file called test, but if I rename the file to Test.dbf it works fine. I can't really rename the file all the time because a third party application uses it as its file format.

Does anyone know a way to read a dbase file without a standard extension in C#.

Thanks.

© Stack Overflow or respective owner

Related posts about c#

Related posts about oledb