webforms - 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:
解决方案
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 文件中成功读取数据,如下图所示:
推荐阅读
- python - 如何用该组的平均值填充非整数,并将所有 NaN 组替换为 0
- sql - 从表中检索数据
- git - 从跟踪远程分支更新本地分支而不丢失本地分支中的更改
- laravel - 访客用户的门禁能力定义不工作
- javascript - Vue - 如何为文本区域和输入字段创建交互式功能?
- javascript - 为什么将新节点添加到链表后,prev 节点设置为 Circular 而不是 _Node?
- c - 确定递归函数的复杂度
- java - Getting the exact timestamp from oracle database using jdbc
- docker - Facing issues while updating BotiumBox 2.5.0 community edition
- java - Apache Camel 中的类型转换错误