![](/img/trans.png)
[英]VB.NET: Load data from a MySQL database into a DataGridView control
[英]Load excel to datagridview using vb.net as language and MySQL as Database
我看了一個教程,所有的代碼都復制了,除了路徑。 但是我收到錯誤消息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
我希望有人能幫助我。 謝謝
由於使用的是.xlsx文件,因此需要使用ACE.OLDB.12.0驅動程序:
Provider = Microsoft.ACE.OLEDB.12.0;數據源= G:\\ Book1.xlsx;擴展屬性= Excel 12.0“
請注意,源是使用和分配的,並且使用“ =”號,而不是冒號“:”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.