【问题标题】:IErrorInfo.GetDescription failed with E_FAIL(0x80004005) in asp.net c#?IErrorInfo.GetDescription 在 asp.net c# 中因 E_FAIL(0x80004005) 而失败?
【发布时间】:2017-02-27 15:31:26
【问题描述】:

我正在尝试读取 excel 文件并将文件的内容转换为数据表,但我不断收到此异常 IErrorInfo.GetDescription failed with E_FAIL(0x80004005) 指向特定行POCCommand.Fill(dt);这是我尝试过的远的。我可能做错了什么?

string POCpath = @"p.xlsx";
 string POCConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + POCpath + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=1\";";

    OleDbConnection POCcon = new OleDbConnection(POCConnection);
    OleDbCommand POCcommand = new OleDbCommand();
    DataTable dt = new DataTable();
    OleDbDataAdapter POCCommand = new OleDbDataAdapter("select * from [Sheet1$] ", POCcon);
    POCCommand.Fill(dt);
    Console.WriteLine(dt.Rows.Count);

【问题讨论】:

标签: c# asp.net


【解决方案1】:

首先,由于您使用的是 .NET,因此您需要将从 IDisposable 继承或实现的任何内容包装到 using 语句中。

如:

using (OleDbConnection connection = new OleDbConnection("connectionstring")){
    //Do stuff here
}

第二: 请在此SO Answer 上参考MethodMan 的出色答案。 它拥有您需要知道的一切。他同时进行 OleDb 连接和 TextFieldParser,这将更快且更便宜。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-27
    • 2023-03-04
    • 2011-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    • 2020-08-08
    相关资源
    最近更新 更多