【问题标题】:Getting different errors while importing Excel file through SqlBulkCopy通过 SqlBulkCopy 导入 Excel 文件时出现不同的错误
【发布时间】:2012-09-20 10:21:00
【问题描述】:

我正在使用 SqlBulkCopy 将 Excel 文件导入 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);

我还需要为任何版本的 Excel 兼容此代码。

我怎样才能做到这一点并解决我的错误?

【问题讨论】:

    标签: c# sql excel


    【解决方案1】:

    我有类似的问题。检查文件路径是否正确

    喜欢

    C:\\file.xls
    

    作为测试。

    还要检查版本是否正确。 8.0 已经很老了,我认为这就像 Office 2000,不是吗?

    【讨论】:

      猜你喜欢
      • 2019-12-28
      • 1970-01-01
      • 2013-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-28
      • 2019-12-17
      • 1970-01-01
      相关资源
      最近更新 更多