类型“System.Data.OleDb.OleDbException”未处理的异常出现在system.data.dll我得到抛出异常,当我尝试运行此代码。(进口到SQL数据库)
更多信息:外部表格不是预期的格式。
if (comboBox1.SelectedItem.ToString() == "Comissioned Sites")
{
string pathConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + txtFilePath.Text + ";Extended Properties=\"Excel 8.0;HDR=Yes;\";";
// Create Connection to Excel Workbook
using (OleDbConnection connection = new OleDbConnection(pathConn))
{
OleDbCommand command = new OleDbCommand("Select * FROM [" + txtSheet.Text + "$]", connection);
connection.Open();
// Create DbDataReader to Data Worksheet
using (OleDbDataReader dr = command.ExecuteReader())
{
// Bulk Copy to SQL Server
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(con))
{
con.Open();
bulkCopy.DestinationTableName = "tblView";
bulkCopy.WriteToServer(dr);
con.Close();
}
}
}
MessageBox.Show("File Imported to Database Successfully");
}
谁能帮助我
如果您使用Excel 2007,http://stackoverflow.com/questions/1139390/excel-external-table-is-not-in-the-expected-format – 2015-02-24 13:05:19
不,我使用excel 2013. – 2015-02-24 13:09:21