reading dbase file without standard .dbf extension.
- by Nathan W
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.