C# 读取dbf报错

.Net技术 码拜 8年前 (2016-03-11) 1842次浏览
DBF Viewer2000 可以正常打开、Visual FoxPro 6.0打开提示不是一个表。
C# 读取dbf报错
C# 读取dbf报错
以下是C#代码,求大神指点!

 //DataSet dataSet = new DataSet();
            DataTable dt = new DataTable();
            //string connectString = string.Format(
            //    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=dBASE IV;User ID=Admin;Password=;", path);
            string connectString = string.Format(
             "Provider=VFPOLEDB.1;Data Source={0};Collating Sequence=MACHINE", path);
            using (OleDbConnection connection = new OleDbConnection(connectString))
            {
                
                try
                {
                    connection.Open();
                 
                    OleDbDataAdapter adapt = new OleDbDataAdapter();
                    adapt.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                    adapt.SelectCommand = new OleDbCommand(sql, connection);
                    adapt.Fill(dt);
                    adapt.Dispose();
                    DataView dv = dt.DefaultView;
                    dv.Dispose();
                    connection.Close();
                    //connection.Open();
                    //OleDbDataAdapter command = new OleDbDataAdapter(sql, connection);
                    //if (command != null)
                    //{
                    //    command.Fill(dataSet);
                    //}
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("error:{0}", ex.Message));
                    return null;
                }
               // return dataSet;
                return dt;

小弟电话:17717606525 感激不尽

解决方案

20

var conn = new OleDbConnection(@”provider=VFPOLEDB.1;Source Type=DBF;data source=.\;user id=admin;password=”);
data source 的值是 dbf 文件所在目录
其他不需要动

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明C# 读取dbf报错
喜欢 (0)
[1034331897@qq.com]
分享 (0)