2
我導入Excel使用SqlBulkCopy
讓不同的錯誤,同時導入Excel文件通過使用SqlBulkCopy
但每次我得到歧這樣的錯誤
時間無法更新文件導入到SQL Server中。數據庫或對象是隻讀的。
或
找不到可安裝ISAM。
或
Microsoft Jet數據庫引擎找不到對象。確保對象存在,並且正確拼寫其名稱和路徑名。
檢查下面我的代碼...
String strConnection = ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString;
string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+filepath+";Extended Properties=Excel 8.0;HDR=YES;";
//Create Connection to Excel work book
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
//Create OleDbCommand to fetch data from Excel
OleDbCommand cmd = new OleDbCommand
("Select * from [Sheet1$]",
excelConnection);
MessageBox.Show("ss");
excelConnection.Open();
MessageBox.Show("ss2");
OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
MessageBox.Show("ss1");
SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
sqlBulk.DestinationTableName = "RecExcelTable";
//sqlBulk.ColumnMappings.Add("ID", "ID");
//sqlBulk.ColumnMappings.Add("Name", "Name");
sqlBulk.WriteToServer(dReader);
此外,我需要這個compitable代碼,任何版本的Excel。
我該怎麼做,解決我的錯誤?