【问题标题】:Error when opening dbf file: External table is not in expected format打开 dbf 文件时出错:外部表不是预期格式
【发布时间】:2013-05-17 05:03:22
【问题描述】:

我正在使用下面的代码来导入一个 dbf 文件。

但我收到一个错误:

'外部表不是预期的格式'

if (ofdDBF.ShowDialog()==DialogResult.OK) 
{ 
   string connStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ofdDBF.FileName.Substring(0, ofdDBF.FileName.LastIndexOf("\\")) + ";Extended Properties=dBASE IV;";     
   OleDbConnection conn = new OleDbConnection(connStr); 
   conn.Open();

   string cmd_string = "select * from " + ofdDBF.SafeFileName.Substring(0, ofdDBF.SafeFileName.IndexOf(".")); 
   MessageBox.Show(cmd_string); 
   OleDbDataAdapter da = new OleDbDataAdapter(cmd_string, conn); 
   DataSet ds = new DataSet(); 
   da.Fill(ds); 
   dgvImport.DataSource = ds.Tables[0]; 
} 

有什么帮助吗?

【问题讨论】:

标签: c# .net dbf


【解决方案1】:

同样的问题(在 64 位系统上),解决方案

下载:http://download.microsoft.com/download/b/f/b/bfbfa4b8-7f91-4649-8dab-9a6476360365/VFPOLEDBSetup.msi

string connString = @"Provider=vfpoledb;Data Source=C:\Directory;Collating Sequence=machine;";
        using (OleDbConnection con = new OleDbConnection(connString))
        {
            con.Open();

                OleDbCommand command = new OleDbCommand("Select * from Table.DBF", con);
                OleDbDataReader reader = command.ExecuteReader();
                ...
        }

【讨论】:

    【解决方案2】:

    在处理 dBase/FoxPro 的数据源时,源通常指的是数据库名称,或者只是路径。

    打开后就可以了

    从 YourTable 中选择 *

    (查询中不需要.dbf文件名后缀。它将通过查看路径或连接的数据库自行解析)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多