使用vb.net作为语言并将MySQL作为数据库加载到datagridview

时间:2015-09-27 12:24:41

标签: mysql vb.net excel datagridview

我观看了一个教程,除了路径之外,所有代码都被复制了。但是我在 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

我希望有人能帮助我。感谢

1 个答案:

答案 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;