You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C#读写FoxPro数据库(.DBF文件)遇连接读取问题求助

C#连接、读写FoxPro数据库问题求助

驱动尝试情况

  • Visual FoxPro ODBC驱动:已停止支持,官方推荐使用Visual FoxPro OLE DB。
  • Visual FoxPro OLE驱动:在Windows x86环境运行时提示‘VFPOLEDB提供程序未在本地机器上注册’,dll文件存在于C:\Program Files (x86)\Common Files\System\Ole DB路径下,推测仅支持32位系统,不兼容64位。
  • Access Manager OLE驱动:能成功连接,但读取表时提示‘外部表不是预期格式’,推测是连接时使用了dBase IV导致的。

代码片段

static void Main(string[] args)
{
    OleDbConnection conn = null;

    try
    {
        // Option 1.1) Free table directory - ACE OLE
        conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\AutoParts\\db;Extended Properties=dBase IV;");

        // Option 1.2) Free table directory - VFPOLE
        // conn = new OleDbConnection("Provider=VFPOLEDB;DRIVER=Microsoft Visual FoxPro Driver;Data Source=D:\\AutoParts\\db;Collating Sequence=machine;");

        // Option 2.1) Database Container - ACE OLE
        // conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\AutoParts\\db2;Extended Properties=dBase IV;");

        // Option 2.2) Database Container - VFPOLE
        // conn = new OleDbConnection("Provider=VFPOLEDB;DRIVER=Microsoft Visual FoxPro Driver;Data Source=D:\\AutoParts\\db2;Collating Sequence=machine;");

        conn.Open();
        Console.WriteLine(conn);

        string strQuery = "Select * from Employee.dbf";

        OleDbCommand myQuery = new OleDbCommand(strQuery, conn);
        OleDbDataAdapter DA = new OleDbDataAdapter(myQuery);
        Console.WriteLine(DA);
 
        using (var reader = myQuery.ExecuteReader())
        {
            while (reader.Read())
            {
                 var str = (string)reader["empl_id"];
                 Console.WriteLine(str);
            }
        }
    }
    finally
    {
        conn.Close();  
    }
}

内容的提问来源于stack exchange,提问作者user22320197

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 13:10:24