我观看了一个教程,除了路径之外,所有代码都被复制了。但是我在 cn.open()
中收到错误无法找到可安装的ISAM以下是整体代码:
Imports System.Data.OleDb
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OlEDB.4.0; Data Source:G:\Book1.xlsx;Extend Properties=Excel 8.0;")
cn.Open() <--Error Here
Dim da As New OleDbDataAdapter("Select * from [Sheet1$]", cn)
Dim dt As New DataTable
With DataGridView1
.AllowUserToAddRows = False
.DataSource = dt
End With
dt.Dispose()
dt = Nothing
da.Dispose()
da = Nothing
With cn
.Close()
.Dispose()
End With
cn = Nothing
End Sub
End Class
我希望有人能帮助我。感谢
答案 0 :(得分:0)
由于您使用的是.xlsx文件,因此需要使用ACE.OLDB.12.0驱动程序:
Provider = Microsoft.ACE.OLEDB.12.0; Data Source = G:\ Book1.xlsx; Extended Properties = Excel 12.0&#34;
注意使用和&#34; =&#34;分配来源。标志,而不是冒号&#34;:&#34;