导入Excel提供错误“System.InvalidOperationException:Microsoft.Jet.OLEDB.4.0”提供程序未注册“
我有一个旧项目运行良好。 现在,我试图从Excel导入时出现错误:
System.Invalidoperationexception“microsoft.jet.oledb.4.0”提供程序未注册
我可以login。 我试图改变项目的平台到x86 / x64 /任何CPU,但没有用。 我也改变了:
Provider = Microsoft.Jet.OLEDB.4.0;数据源
至
Provider = Microsoft.Jet.OLEDB.12.0; Data Source
但没用。 这是我导入Excel的代码:
private void button1_Click_1(object sender, EventArgs e) { // string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\BILL REGISTER 97.xls;Extended Properties=\"Excel 8.0;HDR=Yes;\";"; //string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + txtfilepath.Text + ";Extended Properties=\"Excel 8.0;HDR=Yes;\";"; string connStr = "Provider=Microsoft.Jet.OLEDB.12.0;Data Source=" + txtfilepath.Text + ";Extended Properties=\"Excel 8.0;HDR=Yes;\";"; OleDbConnection con = new OleDbConnection(connStr); // string strCmd = "select * from [sheet1$A8:P10]"; // string strCmd = "select * from [sheet1$A8:IV65536]"; string strCmd = "select * from [sheet1$A6:IV65536]"; OleDbCommand cmd = new OleDbCommand(strCmd, con); try { con.Open(); ds.Clear(); da.SelectCommand = cmd; da.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { con.Close(); } }
我已经安装了Office2010。
尝试使用
Provider=Microsoft.ACE.OLEDB.12.0;Data Source
代替
Provider=Microsoft.Jet.OLEDB.12.0;Data Source