[英]“Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine” while importing data from Excel sheet to SQL Server using C#
I want to import an Excel sheet into SQL Server using C# My Office version is Microsoft Office 2013 Windows version : Windows 10 I tried to download this tool 2007 Office System Driver: Data Connectivity Components and change CPU to x86 but nothing changed This is my code 我想使用C#将Excel工作表导入SQL Server我的Office版本是Microsoft Office 2013 Windows版本:Windows 10我尝试下载此工具2007 Office system驱动程序:数据连接组件并将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());
}
}
}
Error message : Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine
错误消息: Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine
Your code looks fine. 您的代码看起来不错。 Install this: https://www.microsoft.com/en-us/download/details.aspx?id=23734 安装此程序: https : //www.microsoft.com/zh-cn/download/details.aspx?id=23734
That should fix your problem!! 那应该解决您的问题!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.