簡體   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#

我想使用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());
            }
        }
    }

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

您的代碼看起來不錯。 安裝此程序: https : //www.microsoft.com/zh-cn/download/details.aspx?id=23734

那應該解決您的問題!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM