在Visual Studio中将DBF导入数据表时遇到一些问题。我有以下C#代码:
string FileDBF = "MyFileName.dbf";
string FilePath = "C:\\Folder1\\Folder2\\";
//okay then, first we need to get the DBF - which can be queried like an SQL table
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 id From " + FilePath + FileDBF, CC);
OdbcDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
DataTable dt = new DataTable();
dt.Load(dr);
}
CC.Close();
gvDBF.DataSource = dr;
gvDBF.DataBind();
但是,每次运行它时都会说FROM子句中存在错误(在OdbcDataReader dr = cmd.ExecuteReader();行)。
我知道它是针对该文件的,因为我尝试使用无效的文件名,然后弹出然后说该文件无法找到。