C# C-dbf外部表不是预期的格式

C# C-dbf外部表不是预期的格式,c#,oledb,visual-foxpro,dbf,dbase,C#,Oledb,Visual Foxpro,Dbf,Dbase,我在这里挣扎。我正在尝试从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

我在这里挣扎。我正在尝试从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。请帮帮我


不要否定,因为我已经尝试了所有关于这个问题的堆栈溢出答案。

使用VFPOLEDB驱动程序。Jet或ACE驱动程序无法识别所有dbf表。VFPOLEDB驱动程序是32位的,这意味着您应该在C项目属性/构建目标平台中以x86为目标

void Main()
{
    DataTable YourResultSet = new DataTable();
    string path = @"D:\Sample\Database\client.dbf";

    using (OleDbConnection connection =
    new OleDbConnection("Provider=VFPOLEDB;Data Source=" + Path.GetDirectoryName(path)))
    using (OleDbCommand command = new OleDbCommand(
    string.Format("select id from {0}", Path.GetFileNameWithoutExtension(path)), connection))
    {
    connection.Open();
    YourResultSet.Load(command.ExecuteReader());
    connection.Close();
    }

    Form f = new Form();
    DataGridView dgv = new DataGridView { Dock = DockStyle.Fill, DataSource=YourResultSet};
    f.Controls.Add(dgv);
    f.Show();
}

您是否尝试过在select语句中使用表名,如select id from client?你也会犯同样的错误吗?哪一行导致了错误?是的,我也尝试过这个查询。但没有改善。同样的错误也会出现。执行读卡器语句时会出现错误。您好,谢谢您宝贵的回答。我已经尝试了您的示例代码,并将目标CPU版本设置为x86。但错误是d:\sample\database\client.dbf不是表。。请帮助我。dbf应该是VFP已知格式的xBase表。可能不是,或者标头可能已损坏。您可以通过电子邮件将文件发送给我,以便我可以检查您是否希望在deu dot edu dot trAnd使用cetin dot basoz,顺便说一句,如果它是VFP已知的DBF,您可以使用上的代码VFP代码修复它。