Imports System.Data.OleDb
Public Class 实验二
    Dim conn As OleDbConnection
    Dim ds As New DataSet()
    Dim da As OleDbDataAdapter
    Dim bmb As BindingManagerBase
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ds.Clear()
        Dim selSql As String = "Select * From bookinfo Where Category='" & TextBox1.Text & "'"
        da = New OleDbDataAdapter(selSql, conn)
        da.Fill(ds, "bookinfo")    '将记录集填充到ds中
    End Sub

    Private Sub 实验二_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim str As String = "Provider= Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source =F:\book_manager.mdb" '定义连接字符串
        Dim selCmd As String = "Select * From bookinfo"
        conn = New OleDbConnection(str)    '创建OleDbConnection对象
        conn.Open()     '用Open方法打开数据库
        da = New OleDbDataAdapter(selCmd, conn)  '创建DataAdapter对象da
        da.Fill(ds, "bookinfo")    '将记录集填充到ds中
        conn.Close()
        '将DataGridView控件与数据集ds绑定
        DataGridView1.DataSource = ds.Tables("bookinfo")
    End Sub
End Class