首页 > 解决方案 > Could not find installable ISAM while opening excel file with OLE driver

问题描述

I am getting a "Could not find installable ISAM" error in the asp.net webform using visual basic. I am using .Net 4.6 framework. I tried different combinations of connection strings and I also tried with a single quote on Extended Properties as many online solutions suggested but the error did not go away. My code is as below:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim conn As OleDbConnection
        Dim dta As OleDbDataAdapter
        Dim dts As DataSet
        Dim excel As String
        excel = "C:\Users\ishfaq.babar\Downloads\aaa.xlsx"
        'Dim openfiledialog As New OpenFileDialog
        'conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excel + ";Extended Properties='Excel 12.0;'";")

        conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ishfaq.babar\Downloads\aaa.xlsx;Extended Properties='Excel 12.0;HDR=YES;Persist Security Info=False'")
        dta = New OleDbDataAdapter("select * from [Sheet1$]", conn)
        dts = New DataSet
        dta.Fill(dts, "[Sheet1$]")
        ExcelGridData.DataSource = dta
        ExcelGridData.DataBind()
    End Sub

i got error on line

dta.Fill(dts, "[Sheet1$]")

Moreover,I have installed both versions of ole drivers x64 and X86 and I had installed ole driver by command line as:

accessdatabaseengine /quiet

accessdatabaseengine_X64 /quiet

Because I was getting error from GUI Installer as:

microsoft.ace.oledb.12.0' provider is not registered on the local machine

ScreenShot of installed drivers is as follows:

OLE Drivers.Installed Access database Engine versions

标签: webformsoledboledbconnection

解决方案


ERROR 已自动解决,完全没有代码更改。休息后再次登录我的帐户后,它成功运行:

编辑:

我放在conn.Open()连接字符串之后。

新代码如下:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim conn As OleDbConnection
        Try

            Dim dta As OleDbDataAdapter
            Dim dts As DataSet
            Dim excel As String
            excel = "C:\Users\ishfaq.babar\Downloads\aaa.xlsx"
            'Dim openfiledialog As New OpenFileDialog
            'conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excel + ";Extended Properties='Excel 12.0;'";")

            conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ishfaq.babar\Downloads\aaa.xlsx;Extended Properties='Excel 12.0;HDR=YES;Persist Security Info=False'")
            conn.Open()
            'PrintLine('ok')
            ' conn.Close()
            dta = New OleDbDataAdapter("select * from [Sheet1$]", conn)
            dts = New DataSet
            dta.Fill(dts, "[Sheet1$]")
            ExcelGridData.DataSource = dta
            ExcelGridData.DataBind()
        Catch ex As Exception
            conn.Close()
        End Try
    End Sub

从 excel 文件中成功读取数据,如下图所示:

从excel文件中读取数据的结果


推荐阅读