先去下载并安装VFPOLEDBSetup.msi,网上很多。
OpenFileDialog openDialog = new OpenFileDialog();
openDialog.Filter = "Dbf(*.dbf)|*.dbf|ALL Files(*.*)|*.*";
openDialog.Title = "选择表数据";
if(DialogResult.OK == openDialog.ShowDialog())
{
string strDbfPath = openDialog.FileName;
FileInfo fi = new FileInfo(strDbfPath);
string mulu = fi.DirectoryName;
string filename = fi.Name;
OleDbConnection conn = new OleDbConnection();
string connStr = "Provider = VFPOLEDB.1; Data Source = "+ mulu +"; Collating Sequence = MACHINE";
conn.ConnectionString = connStr;
conn.Open();
string sql = "select * from" + strDbfPath;
OleDbDataAdapter da = new OleDbDataAdapter(sql, conn);
DataTable dt = new DataTable();
da.Fill(dt);
}
(引用处要添加using System.Data.OleDb )