C# 导入Excel时出现错误“;System.InvalidOperationException:Microsoft.Jet.OLEDB.4.0';“供应商未注册”;
我有一个运行良好的老项目。现在,我在尝试从Excel导入时遇到错误: System.Invalidoperationexception未注册“microsoft.jet.oledb.4.0”提供程序 我可以登录。我尝试将项目的平台更改为x86/x64/任何CPU,但没有任何用处。 我也改变了: Provider=Microsoft.Jet.OLEDB.4.0;数据源 到 Provider=Microsoft.Jet.OLEDB.12.0;数据源 但是没有用。以下是我导入Excel的代码:C# 导入Excel时出现错误“;System.InvalidOperationException:Microsoft.Jet.OLEDB.4.0';“供应商未注册”;,c#,.net,excel,oledb,C#,.net,Excel,Oledb,我有一个运行良好的老项目。现在,我在尝试从Excel导入时遇到错误: System.Invalidoperationexception未注册“microsoft.jet.oledb.4.0”提供程序 我可以登录。我尝试将项目的平台更改为x86/x64/任何CPU,但没有任何用处。 我也改变了: Provider=Microsoft.Jet.OLEDB.4.0;数据源 到 Provider=Microsoft.Jet.OLEDB.12.0;数据源 但是没有用。以下是我导入Excel的代码: p
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
哪个版本的Office?64位还是32位?如何检查?如果Office是32位,那么您应该使用ACE.12.0并为x86编译应用程序。(或任何32位CPU)看看这个答案,它可以帮助理解情况