我正在嘗試使用.NET和Winforms來讀取dBase III .dbf文件,而我試過的東西似乎都不起作用。我嘗試了四種不同的連接方法,並且它們中的每一個都掛在Open
方法上。沒有例外,沒有超時,沒有事件消息,什麼都沒有。表格就在那裏。關於什麼可能是錯誤的任何想法?與dBase .dbf文件的.NET連接
這是我試過的方法。 .dbf文件是在d:\ DB:
private void read1()
{
string c = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\db\\;Extended Properties=dBASE III";
OleDbConnection conn = new OleDbConnection(c);
conn.Open();
MessageBox.Show("ok");
conn.Close();
}
private void read2()
{
System.Data.Odbc.OdbcConnection oConn = new System.Data.Odbc.OdbcConnection();
oConn.ConnectionString = @"Driver={Microsoft dBase Driver (*.dbf)};SourceType=DBF;SourceDB=D:\db;Exclusive=No; Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";
oConn.Open();
System.Data.Odbc.OdbcCommand oCmd = oConn.CreateCommand();
oCmd.CommandText = @"SELECT * FROM D:\db\Poi.dbf";
DataTable dt = new DataTable();
dt.Load(oCmd.ExecuteReader());
MessageBox.Show(dt.Rows.Count.ToString());
oConn.Close();
}
private void read3()
{
System.Data.Odbc.OdbcConnection oConn = new System.Data.Odbc.OdbcConnection();
oConn.ConnectionString = @"Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=d:\db;";
oConn.Open();
MessageBox.Show("ok");
oConn.Close();
}
private void read4()
{
System.Data.Odbc.OdbcConnection oConn = new System.Data.Odbc.OdbcConnection();
oConn.ConnectionString = @"Driver={Microsoft dBase Driver (*.dbf)};datasource=d:\db\";
oConn.Open();
System.Data.Odbc.OdbcCommand oCmd = oConn.CreateCommand();
oCmd.CommandText = @"SELECT * FROM D:\db\Poi.dbf";
DataTable dt = new DataTable();
dt.Load(oCmd.ExecuteReader());
MessageBox.Show(dt.Rows.Count.ToString());
oConn.Close();
}
我想幫忙,但在那裏我找到了DBF檔案這幾天? =) –