注册 登录
编程论坛 VB.NET论坛

有关于选择查询

花籽 发布于 2012-11-28 10:08, 562 次点击
只有本站会员才能查看附件,请 登录

代码应该怎样写?
2 回复
#2
fily13142012-11-30 23:07
判断姓名的checked是否为true,是的话textbox里的内容就到姓名列去查询,否则就到学号列去查询
#3
ZMGTCDY2012-12-03 08:11
Private Sub 查询Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 查询Button.Click
        Dim testCheck1 As Boolean
        Dim testCheck2 As Boolean
        testCheck1 = CheckBox1.Checked
        testCheck2 = CheckBox2.Checked
       If testCheck1 = True Then
            Dim MySQLConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\****.accdb;Jet OLEDB:Database Password=*****"                   Dim MyConnection As New System.Data.OleDb.OleDbConnection(MySQLConnectionString)
            MyConnection.Open()
            Dim MyTable As New Data.DataTable()
            Dim MySQL As String = "select * from 学生管理  where (姓名= '" + Me.姓名TextBox.Text + "')"
            Dim MyAdapter As New OleDbDataAdapter(MySQL, MyConnection)
            MyAdapter.Fill(MyTable)
            Me.学生管理DataGridView.DataSource = MyTable
            If (MyConnection.State = ConnectionState.Open) Then
                MyConnection.Close()
            End If
         Else
           同理
         End If
End Sub
1