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中,代码要改那里?