LinqToExcel有时导致IErrorInfo.GetDescription失败并带有E_FAIL(0x80004005)

时间:2012-06-29 13:26:57

标签: .net excel linq-to-excel

有时,在运行下面的代码时,调用IErrorInfo.GetDescription failed with E_FAIL(0x80004005)会导致错误excelFile.WorksheetNoHeader(0)

它似乎不依赖于excel文件,一个文件可以读取一次,下一次不可读。

任何想法可能是什么原因?

    Public Overrides Function GetImportDataAsDataTable() As DataTable
        Dim dataTable = New DataTable
        dataTable.BeginLoadData()
        Try
            Dim excelFile = New ExcelQueryFactory(FileFullPath)
            For Each importDataRow In excelFile.WorksheetNoHeader(0)
                If dataTable.Columns.Count = 0 Then
                    For i = 1 To importDataRow.Count
                        dataTable.Columns.Add(New DataColumn())
                    Next
                End If
                Dim dataRow = dataTable.NewRow
                dataRow.ItemArray = importDataRow.ToArray
                dataTable.Rows.Add(dataRow)
            Next
        Finally
            dataTable.EndLoadData()
        End Try
        Return dataTable
    End Function

1 个答案:

答案 0 :(得分:1)

这是OleDb错误。

看起来像是使用了保留的sql词。有关更多信息,请查看此帖子:http://forums.asp.net/t/1225443.aspx/1