大家好,我是新手,还是开始学习代码 我创建了一个表单,并使用datagridview来存储数据库数据,还创建了搜索文本框和搜索按钮。但是我想在上面放一个过滤器 如果用户要从Diamond班级搜索学生姓名,则他们在第一个组合框中选择Diamon。现在他们想从状态为“缺席”的钻石级学生中搜索学生姓名,因此他们在第二个文本框中输入“缺席”,数据网格显示状态为“缺席”的钻石级学生。 你能帮我吗 我作为初学者使用vb.net第一编程语言和ms访问权限? 我不知道你能告诉我如何做吗
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If ComboBox1.Text = "Diamon" Then
If ComboBox2.Text = "StudentName" Then
Attendance()
End If
End If
End Sub
Public Sub Attendance()
Try
Dim sCon As String = String.Format("Provider= Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\db.accdb")
Dim str As String = "SELECT * FROM dbtable WHERE Attendance = @A1"
Dim dt As New DataTable
Using con1 As OleDbConnection = New OleDbConnection(sCon)
con1.Open()
Using cmd1 As OleDbCommand = New OleDbCommand(str, con1)
With cmd1.Parameters
.Add("@A", OleDbType.VarChar).Value = TextBox1.Text
End With
Dim adp As New OleDbDataAdapter(cmd1)
adp.Fill(dt)
DataGridView1.DataSource = dt
End Using
con1.Close()
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub