【发布时间】:2017-02-27 06:37:26
【问题描述】:
我在这里挣扎。我正在尝试从 dbf 文件中获取数据。使用下面的连接字符串和代码。
DataTable YourResultSet = new DataTable();
const string path = "D:\\Sample\\Database\\client.dbf";
string conStr = String.Format("Provider = Microsoft.Jet.Oledb.4.0; Data Source = {0}; Extended Properties = \"dBase IV\"", Path.GetDirectoryName(path));
var connection = new OleDbConnection(conStr);
connection.Open();
var command = new OleDbCommand(string.Format("select id from {0}", Path.GetFileName(path)), connection);
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
var str = (string)reader["id"];
}
}
connection.Close();
很少有 dbf 文件可以读取,大部分 dbf 文件无法获取。执行代码时出现 “外部表不是预期格式”的错误。
即使我使用不同的连接字符串,如 vfopledb、vfoledb1、jet、ace 等。
我的机器是 64 位的,我使用的是 vs2013。请帮帮我。
不要否定,因为我已经尝试了关于同一问题的所有堆栈溢出答案。
【问题讨论】:
-
您是否尝试过在您的选择语句中使用表名,例如
select id from client?你得到同样的错误吗?哪一行导致错误? -
是的,我也尝试过该查询。但没有改善。会有同样的错误。执行 reader 语句时会出现错误。
标签: c# oledb visual-foxpro dbf dbase