我試圖從Excel中將一些數據導入數據庫。我從http://www.davidhayden.com/blog/dave/archive/2006/05/31/2976.aspx得到以下代碼。我有一個x86架構,所以這不是問題。當我運行代碼時,程序在connection.Open();
上說,「Microsoft.Jet.OLEDB.4.0」提供程序未在本地計算機上註冊。有任何想法嗎 ?「Microsoft .Jet.OLEDB.4.0」提供程序未在本地計算機上註冊
string excelConnectionString = @"Provider=Microsoft
.Jet.OLEDB.4.0;Data Source=C://suc.xls;Extended
Properties=""Excel 8.0;HDR=YES;""";
// Create Connection to Excel Workbook
using (OleDbConnection connection =
new OleDbConnection(excelConnectionString))
{
OleDbCommand command = new OleDbCommand
("Select ID,Data FROM [Data$]", connection);
connection.Open();
// Create DbDataReader to Data Worksheet
using (DbDataReader dr = command.ExecuteReader())
{
// SQL Server Connection String
string sqlConnectionString = "Data Source=.;Initial Catalog=Test;Integrated Security=True";
// Bulk Copy to SQL Server
using (SqlBulkCopy bulkCopy =
new SqlBulkCopy(sqlConnectionString))
{
bulkCopy.DestinationTableName = "ExcelData";
bulkCopy.WriteToServer(dr);
}
}
}
我已經指定我使用32位機器 – Alex 2010-11-18 11:49:37
謝謝。這對我有效。 – Narnian 2012-09-21 15:47:43