简体   繁体   English

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

[英]“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.

相关问题 'Microsoft.ACE.OLEDB.12.0' 提供程序未在本地计算机(服务器)上注册 - The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine (server) c# Excel,未注册提供程序“microsoft.ace.oledb.12.0” - c# Excel, the provider 'microsoft.ace.oledb.12.0' is not registered 从 excel 导入错误 Microsoft.ACE.OLEDB.12.0 提供程序未在本地机器上注册 - Import from excel error Microsoft.ACE.OLEDB.12.0 provider is not registered on the local machine 未在本地计算机上注册“ Provider = Microsoft.ACE.OLEDB.12.0”提供程序 - The 'Provider=Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine Microsoft.ACE.OLEDB.12.0'提供程序未在C#应用程序的本地计算机上注册错误 - Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine error in C# application “ Microsoft.ACE.OLEDB.12.0”提供程序未在本地计算机上注册。 C# - The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine. c# 将数据导出到 MS ACCESS 时,“Microsoft.ACE.OLEDB.12.0”提供程序未在本地计算机上注册 - The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine while data export to MS ACCESS microsoft.ace.oledb.12.0提供程序未在本地计算机上注册 - the microsoft.ace.oledb.12.0 provider is not registered on the local machine “'Microsoft.ACE.OLEDB.12.0' 提供程序未在本地计算机上注册” - "The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine" 'Microsoft.ACE.OLEDB.12.0' 提供程序未在本地计算机上注册 - The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM