“Microsoft.ACE.OLEDB.12.0”提供程序未在本地计算机上注册“,而从Excel表导入数据到SQL Server使用C#

我想要导入一个Excel表格到SQL Server使用C#我的Office版本是Microsoft Office 2013 Windows版本:Windows 10我试图下载此工具2007年Office系统驱动程序:数据连接组件 ,并将CPU更改为x86,但没有任何更改这是我的代码

private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e) { button1.Enabled = true; textBox1.Enabled = true; } private void button1_Click_1(object sender, EventArgs e) { of1.Filter = "xls|*.xlsx"; if ((of1.ShowDialog()) == System.Windows.Forms.DialogResult.OK) { imagepath = of1.FileName; //image path textBox1.Text = imagepath.ToString(); } } private void loadbtn_Click(object sender, EventArgs e) { string ssqltable = comboBox1.GetItemText(comboBox1.SelectedItem); string myexceldataquery = "select * from ["+ ssqltable + "$]"; try { string sexcelconnectionstring = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\Work\Bioxcell\UCB.xlsx;Extended Properties=Excel12.0Xml;HDR=YES;"; string ssqlconnectionstring = "Data Source=.;Initial Catalog=Bioxcell;Integrated Security=True"; OleDbConnection oledbconn = new OleDbConnection(sexcelconnectionstring); OleDbCommand oledbcmd = new OleDbCommand(myexceldataquery, oledbconn); oledbconn.Open(); OleDbDataReader dr = oledbcmd.ExecuteReader(); SqlBulkCopy bulkcopy = new SqlBulkCopy(ssqlconnectionstring); bulkcopy.DestinationTableName = ssqltable; while (dr.Read()) { bulkcopy.WriteToServer(dr); } oledbconn.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } 

错误消息: Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine

你的代码看起来很好。 安装此: https : //www.microsoft.com/en-us/download/details.aspx?id=23734

这应该解决你的问题!