在使用OLE驱动程序打开excel文件时无法找到可安装的ISAM



提示"无法找到可安装的isam ";在使用visual basic的asp.net web表单中出现错误。我使用的是。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:Usersishfaq.babarDownloadsaaa.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:Usersishfaq.babarDownloadsaaa.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。填充(dts,"[Sheet1 $]")

此外,我已经安装了两个版本的ole驱动程序x64和X86,我已经安装了ole驱动程序命令行:

accessdatabaseengine /quiet

accessdatabaseengine_X64 /quiet

因为我从GUI Installer得到错误:

microsoft.ace.oledb.12.0'提供程序未在本地机器上注册

已安装的驱动程序截图如下:

OLE司机。已安装Access数据库引擎版本

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:Usersishfaq.babarDownloadsaaa.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:Usersishfaq.babarDownloadsaaa.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文件中读取数据的结果

相关内容

  • 没有找到相关文章

最新更新