c# 通过 OLEDB连接Access,DBF。

64位程序需要下载 驱动 AccessDatabaseEngine_X64.exe 

32位程序需要下载 驱动 AccessDatabaseEngine.exe 

官方下载地址:https://www.microsoft.com/zh-cn/download/details.aspx?id=13255

 

要与安装的office版本一直

64位链接

    this.connstring = string.Format("Provider = Microsoft.ACE.OLEDB.12.0 ;Data Source ={0};Extended Properties=dBASE IV;", filePath);
    this.Connection = new OleDbConnection(connstring);

32位链接

    this.connstring = string.Format("Provider = Microsoft.Jet.OLEDB.4.0 ;Data Source ={0};Extended Properties=dBASE IV;", filePath);
    this.Connection = new OleDbConnection(connstring);

基本代码

     this.Connection = new OleDbConnection(connstring);    
     OleDbCommand dc = Connection.CreateCommand();
    Connection.Open();
     dc.CommandText = Sql;
     int count = dc.ExecuteNonQuery();
     Connection.Close();
     dc.Dispose();

另外:Microsoft.ACE.OLEDB.12.0 可以访问正在打开的 Excel 文件,而 Microsoft.Jet.OLEDB.4.0 是不可以的。

更多链接字符串:https://www.connectionstrings.com/dbf-foxpro/

posted @ 2017-04-25 10:51  Alan_YN  阅读(2340)  评论(0编辑  收藏  举报