Label |
Textbox
|
Button |
DataGridview |
Imports System.Data.OleDb
Public Class Form1
Dim conn As OleDbConnection
Dim da As OleDbDataAdapter
Dim ds As New DataSet
Private Function GetConnection() As OleDbConnection
Return New OleDbConnection(My.Settings.personConnectionString)
End Function
Private Function CreateDataAdpater(ByVal strcomm As String, ByVal conn As OleDbConnection) As OleDbDataAdapter
Return New OleDbDataAdapter(strcomm, conn)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strComm As String = "select * from grade where 姓名 like '%" & TextBox1.Text & "%'"
da = CreateDataAdpater(strComm, GetConnection)
da.Fill(ds, "grade")
DataGridView1.DataSource = ds.Tables("grade")
DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
End Sub
End Class