DBF External table is not in the expected format DBF External table is not in the expected format DBF External table is not in the expected format
I has a problem with opening DBF file. I thought, it is dBase file, but it is FoxPro file.
Download and install FoxPro driver (for example http://www.fishr.cz/download/vfpoledb.exe)
Use this code:
OleDbConnection oleDbConnection1 = new OleDbConnection("Provider=VFPOLEDB.1;" + "Data Source=C:\\myVFPDatabase.DBC;"); oleDbConnection1.Open();
OLD METHOD (dBase 3, 4):
public static DataSet dataSetFromDBF(string soubor)
{
DataSet ds = null;
string directory;
string fileName;
directory = System.IO.Path.GetDirectoryName(soubor);
fileName = System.IO.Path.GetFileName(soubor);
try
{
//"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\folder;Extended Properties=dBASE IV;User ID=Admin;Password="
string connectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + directory + ";" +
"Extended Properties=\"dBASE IV\";User ID=Admin;Password=";
string selectCommand = "select * from " + fileName + " ";
OleDbConnection oCon = new OleDbConnection(connectionString);
OleDbDataAdapter oDa = new OleDbDataAdapter(selectCommand, oCon);
ds = new DataSet();
oDa.Fill(ds, fileName);
}
catch(OleDbException oExc)
{
Soubor.logovat("Došlo k chybě (ole) při práci s DBF souborem.");
throw new Exception(oExc.Message);
}
catch(Exception exc)
{
Soubor.logovat("Došlo k chybě při práci s DBF souborem.");
throw new Exception(exc.Message);
}
return ds;
} DBF External table is not in the expected format