标题:dbf文件导入datagridview老是出错,?
取消只看楼主
jm1ghpef
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-9-22
结帖率:83.33%
已结贴  问题点数:20 回复次数:1 
dbf文件导入datagridview老是出错,?
代码如下:
        private void Import()
        {
            openFileDialog1.CheckFileExists = true;  //验证路径有效性
            openFileDialog1.CheckPathExists = true; //验证文件有效性
            OpenFileDialog ofd = new OpenFileDialog();
            try
            {
                //if (open.ShowDialog() == DialogResult.OK)
                if(openFileDialog1.ShowDialog() ==DialogResult.OK)
                {
                    string  source = openFileDialog1.FileName;
                    this.Text = source;
                    string connstr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +source+";Extended Properties=dBASE IV;";
                    string sel = "select * from " + openFileDialog1.FileName;
                    OleDbCommand olecmd = new OleDbCommand(sel, new OleDbConnection(connstr));
                    OleDbDataAdapter olesda = new OleDbDataAdapter(olecmd);
                    DataSet ds = new DataSet();
                    olesda.Fill(ds);
                    this.dataGridView1.DataSource = ds.Tables[0];
                    ds.Dispose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }

自定义一个方法把dbf文件导入datagridview,通过openfiledialog获得文件的路径了,但老是报错:请确认文件的有效性,和连接的问题?
大家帮我看一下,是代码的连接字符串有问题,还是有其他的问题?
再问一个问题,假如把dbf文件导入datagridview后,想要把datagridview的数据添加到SQL中,代码要改那里?
搜索更多相关主题的帖子: dbf datagridview 文件 
2009-07-25 16:54
jm1ghpef
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-9-22
得分:0 
这个表名是通过openfiledialog获得的,,,,,,,,,


知道的朋友可以说一下吗?
2009-07-26 13:25



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-280507-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.248487 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved