public DataSet GetDbfData(string sFileName,string tableName)
{
//string strConnection = @"Dsn=Visual FoxPro Tables;sourcedb=" + sFileName.Substring(0, sFileName.LastIndexOf("//")) + ";sourcetype=DBF;exclusive=No;backgroundfetch=Yes;collate=Machine";
string strConnection = GetConnection(sFileName);
//对于连接串,注意版本问题
string strSelect = "SELECT * FROM " + tableName + " WHERE THISNUM > 0 ";
OleDbConnection thisConnection = new OleDbConnection(strConnection);
thisConnection.Open();
OleDbDataAdapter thisAdapter = new OleDbDataAdapter(strSelect, thisConnection);
DataSet thisDataSet = new DataSet();
try
{
thisAdapter.Fill(thisDataSet);
}
catch (Exception exec)
{
MessageBox.Show(exec.Message);
}
return thisDataSet;
}
private string GetConnection(string path)
{
return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=dBASE IV;";
}
本文介绍了一个使用C#实现从DBF文件中读取数据的方法。该方法通过OleDb连接到DBF文件,并使用SQL查询获取所有THISNUM大于0的记录。文章提供了完整的代码示例,包括连接字符串的配置及异常处理。
1747

被折叠的 条评论
为什么被折叠?



