Access数据库不会在VB.NET DGV中显示Button。连接不会打开

时间:2015-09-06 00:01:22

标签: vb.net oledb

Imports System.Data.OleDb
 Public Class Form1

    Dim dbConnection As OleDbCommand
    Dim dbCommand As OleDbCommand
    Dim dbDataAdapter As OleDbDataAdapter
    Dim ConnectString As String = "Provider = Microsoft.ACE.OLEDB.12. , Data    Source = PatientBilling.mdb.accdb "
    Dim dtPatientBillingTable As DataTable
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As  System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub dispAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dispAll.Click
        dbConnection = New OleDbConnection() 
        dbDataAdapter = New OleDbDataAdapter()
        dtPatientBillingTable = New DataTable()
        dbCommand = New OleDbCommand("SELECT * FROM PatientBillingTable")
        dbCommand.CommandType = CommandType.TableDirect
        dbDataAdapter.SelectCommand = dbCommand
        dbDataAdapter.SelectCommand.Connection = dbConnection
        dbConnection.Open() 
        dbDataAdapter.Fill(dtPatientBillingTable)
        DataGridView1.DataSource = dtPatientBillingTable
        dbConnection.Close() 

    End Sub
End Class

- 连接没有打开 - 按钮不起作用

1 个答案:

答案 0 :(得分:0)

尝试更改此内容:

dbConnection = New OleDbConnection() 

到此:

dbConnection = New OleDbConnection(ConnectString)