使用 OLE 驱动程序打开 excel 文件时找不到可安装的 ISAM
Could not find installable ISAM while opening excel file with OLE driver
我在使用 Visual Basic 的 asp.net 网络表单中收到“无法找到可安装的 ISAM”错误。我正在使用 .Net 4.6 框架。我尝试了不同的连接字符串组合,我也尝试在扩展属性上使用单引号作为许多在线解决方案的建议,但错误并没有消失。我的代码如下:
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
我在线上遇到错误
dta.Fill(dts, "[Sheet1$]")
此外,我已经安装了 ole 驱动程序 x64 和 X86 的两个版本,并且我已经通过 命令行 安装了 ole 驱动程序:
accessdatabaseengine /quiet
accessdatabaseengine_X64 /quiet
因为我从 GUI Installer 收到错误消息:
microsoft.ace.oledb.12.0' provider is not registered on the local machine
驱动安装截图如下:
OLE Drivers.Installed Access database Engine versions
错误已自动解决,根本没有更改代码。休息后再次登录我的帐户后,它运行成功:
编辑:
我把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 文件中读取数据,如下图所示:
Result of data read from excel file
我在使用 Visual Basic 的 asp.net 网络表单中收到“无法找到可安装的 ISAM”错误。我正在使用 .Net 4.6 框架。我尝试了不同的连接字符串组合,我也尝试在扩展属性上使用单引号作为许多在线解决方案的建议,但错误并没有消失。我的代码如下:
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
我在线上遇到错误
dta.Fill(dts, "[Sheet1$]")
此外,我已经安装了 ole 驱动程序 x64 和 X86 的两个版本,并且我已经通过 命令行 安装了 ole 驱动程序:
accessdatabaseengine /quiet
accessdatabaseengine_X64 /quiet
因为我从 GUI Installer 收到错误消息:
microsoft.ace.oledb.12.0' provider is not registered on the local machine
驱动安装截图如下:
OLE Drivers.Installed Access database Engine versions
错误已自动解决,根本没有更改代码。休息后再次登录我的帐户后,它运行成功:
编辑:
我把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 文件中读取数据,如下图所示:
Result of data read from excel file