尝试阅读和编写DBF文件,我发现了这个示例:http://www.aspcode.net/reading-dbf-files-in-c
System.Data.Odbc.OdbcConnection oConn = new System.Data.Odbc.OdbcConnection();
oConn.ConnectionString = @"Driver={Microsoft dBase Driver (*.dbf)};SourceType=DBF;SourceDB=D:\databases\;Exclusive=No; Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";
oConn.Open();
System.Data.Odbc.OdbcCommand oCmd = oConn.CreateCommand();
oCmd.CommandText = @"SELECT * FROM D:\databases\thefile.dbf" ;
DataTable dt = new DataTable();
dt.Load(oCmd.ExecuteReader());
oConn.Close();
dataGridView1.DataSource = dt;
如果文件或文件夹名称中包含短划线( - ),则唯一的问题是它不起作用。有没有办法让这个查询在名称中使用短划线?
例如。 DBF文件:C:\Temp\bowlpos\07-10\01-07-10.DBF
答案 0 :(得分:1)
尝试以下
using (OleDbConnection cn = new OleDbConnection(
@"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data Source=C:\Temp\bowlpos\07-10\01-07-10.DBF;" +
@"Extended Properties=dBASE III;"))
using (OleDbCommand cm = cn.CreateCommand())
{
cn.Open();
cm.CommandText = "SELECT * FROM [01-07-10]";
DataTable dt = new DataTable();
dt.Load(cm.ExecuteReader());
dataGridView1.DataSource = dt;
}