连接dbf 提示不能打开文件.dbc
在C#代码中连接Weight.dbf时提示信息不能打开文件scale.dbc,是怎么原因?
我是单把那边的数据库文件Weight.dbf拷贝到本机上调试的
代码如下:
DataSet ReadSJSHQ()
{
//string strConn = @"Provider=vfpoledb;Data Source=D:\Pfrmis\Data\database;Collating Sequence=machine;";
//using (OleDbConnection myConnection = new OleDbConnection(strConn))
//{
// myConnection.Open();
// OleDbDataAdapter adpt = new OleDbDataAdapter("select * from Weight.dbf", myConnection);
// DataSet mySet = new DataSet();
// adpt.Fill(mySet);
// myConnection.Close();
// return mySet;
//}
System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection();
string tb = @"D:\Pfrmis\Data\database\Weight.dbf";
//string connStr = @"Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" + tb + ";Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO";
string connStr = @"Dsn=Visual FoxPro Tables;sourcedb=D:\Pfrmis\Data\database;sourcetype=DBF;exclusive=No;backgroundfetch=Yes;collate=Machine";
//string connStr = @"Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=D:\Pfrmis\Data\database;Exclusive=No;BackgroundFetch=No;";
conn.ConnectionString = connStr;
conn.Open();
string sql = "select * from " + tb;
OdbcDataAdapter da = new OdbcDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
return ds;
}
------解决方案--------------------
说明该dbf文件是该dbc数据库的一部分,属于visual foxpro,不能直接打开,必须打开dbc文件,然后访问该表