Monday, November 26, 2007

C# and DBF files

I have a client that asked me to read DBF files generated by their SAS application. Well, this posting is to explain to someone what i have learned in reading DBF files using C#. The main thing I learned was no spaces in the file path.

Here is the code that worked for me:

string connectionString = "Driver={Microsoft dBase Driver (*.dbf)};SourceType=DBF;SourceDB=C:\projects\Client\Data\WeeklyAvailableComparison;Exclusive=No; Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";
string selectCommand = @"SELECT * FROM C:\projects\Client\Data\WeeklyAvailableComparison\ac_141.dbf";
DataTable dt = new DataTable();

OdbcConnection oConn = new OdbcConnection();
oConn.ConnectionString = connectionString;
OdbcCommand oCmd = oConn.CreateCommand();
oCmd.CommandText = selectCommand;


I tried doing a 8.3 conversion and it wouldn't work for the select clause.

I hope this helps someone.



Vince said...

Alan, I tried this and get a syntax error in the select statement. how did you get by that?

Alan Churchill said...

I don't know what syntax you used or what the error message was so it is hard to comment.


Alexis said...

Yesterday evening I was in difficult situation..all my dbf fiels were lost. For luck in that day I was succeeded and found in the Internet - dbase recover. It solved my problem for seconds and showed me how it restored a maximum of information from damaged DBF tables.

CTRL+Z does not generate EOF in Windows 10

In Windows 10, when I was trying to generate an EOF for a Java program, the CTRL+Z did not work. After doing some research (and help from f...