2012-07-06 69 views

回答

15

您可以創建一個connection string to dbf file,然後使用OLEDB中,你可以填充DataSet,像這樣:

string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=directoryPath;Extended Properties=dBASE IV;User ID=Admin;Password=;"; 
using (OleDbConnection con = new OleDbConnection(constr)) 
      { 
       var sql = "select * from " + fileName; 
       OleDbCommand cmd = new OleDbCommand(sql, con); 
       con.Open(); 
       DataSet ds = new DataSet(); ; 
       OleDbDataAdapter da = new OleDbDataAdapter(cmd); 
       da.Fill(ds); 
      } 

以後可以使用ds.Tables[0]作進一步處理。

您可能還會檢查這篇文章Load a DBF into a DataTable

+0

非常感謝。我可以做我想要的東西! – user1484319 2012-07-06 07:10:06

+2

你應該使用'directoryPath'而不是'yourfilepath'來避免誤導...或者使用特定的例子,例如:'c:\ folder' – Jaider 2015-08-04 20:56:44

+0

是否可以獲取特定的行數據?就像我將傳遞行索引,我應該得到特定的行數據 – 2015-11-11 12:17:52

相關問題