Reputation: 11
I cannot to connect to a DBF file type Visual dBase level 7 format with C#.
I can read a DBF file type dBase III and dBase IV but with the file type DBF Visual dBase 7 Visual studio return an error message:
"the format table is not on right format expected".
Here is the follow codes I use for an console application:
static void Main(string[] args)
{
string filepath = @"C:\Users\user\Desktop\BGF\DATA\";
OdbcConnection CC =
new OdbcConnection("Driver={Microsoft dBase Driver
(*.dbf)};SourceType=DBF;SourceDB=" + filepath + ";Exclusive=No;
Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;");
CC.Open();
OdbcCommand cmd = new OdbcCommand("Select * From MyDBF_file", CC);
OdbcDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
DataTable dt = new DataTable();
dt.Load(dr);
}
CC.Close();
`enter code here`Console.WriteLine("Successful");
Console.Read();
}
I think the provider is not compatible, but I have tried with Microsoft.Jet.OLEDB.4.0 does not work. And with vfpoledb provider same problem.
I have tried with simple query as OdbcCommand cmd = new OdbcCommand("Select * From MyDBF_file", CC);
And same problem :-(
Thx in advance for your help or for all approach contribute to a part of solution ;-)
Upvotes: 1
Views: 2247
Reputation: 118
For Visual dBase level 7 format this connections will not work. You can use code library of dBase IV reader and modify headers to work with Dbase 7 files.
You can find Dbase 7 header information from here.
http://www.dbase.com/KnowledgeBase/int/db7_file_fmt.htm
And DBF reader for older version from here.
https://github.com/eXavera/NDbfReader
Upvotes: 0
Reputation: 48169
You appear to be correct on the CONNECTION. That should be to the PATH where the tables are located. However, you QUERY should
select * from SomeTableWithinThatPath
You are trying to query the PATH, not a specific table.
Upvotes: 0