我有一个 datagrid 控件,其中包含从 MySql 数据库中检索的名称列表。我可以搜索它们,直到我得到一个结果。当结果数等于 1 时,我希望能够显示一个 groupbox 控件。此外,在 groupbox 中,我有一个按钮,单击该按钮将从服务器中删除此用户,并从名为“employee”的 mysql 表中删除他们的信息. 当用户被删除时,我将在消息框中显示一条确认消息,并使用更新的列表重新加载表格。到目前为止,我唯一遇到的两个问题是当结果等于 1 时显示 groupbox 并根据搜索结果的名称从 sql server 中删除用户。我在 Windows 7 笔记本电脑上的 Visual Basic 2010 Express 中使用 vb.net。谢谢!
编辑1:
到目前为止,这是我的代码,请建议我如何将您的答案应用于它。谢谢!
Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
'Search Function.
Dim sqlsearch1 As MySqlCommand = New MySqlCommand("SELECT * FROM employee where name LIKE '%?name%' GROUP BY name;", con)
Dim sqlsearch2 As MySqlCommand = New MySqlCommand("SELECT * FROM employee where title LIKE '%?title%' GROUP BY title;", con)
sqlsearch1.Parameters.AddWithValue("?name", TextBox1.Text)
sqlsearch2.Parameters.AddWithValue("?title", TextBox1.Text)
If RadioName.Checked = True Then
con.Open()
Dim table As DataTable
For Each table In ds.Tables
Next
' Clear all rows of each table.
ds.Clear()
' display results in Datagrid1.
DataAdapter1.SelectCommand = sqlsearch1
DataAdapter1.Fill(ds, "stratos")
DataGrid1.DataSource = ds
DataGrid1.DataMember = "stratos"
con.Close()
Else
End If
If RadioTitle.Checked = True Then
con.Open()
Dim table As DataTable
For Each table In ds.Tables
Next
' Clear all rows of each table.
ds.Clear()
' display results in Datagrid1.
DataAdapter1.SelectCommand = sqlsearch2
DataAdapter1.Fill(ds, "stratos")
DataGrid1.DataSource = ds
DataGrid1.DataMember = "stratos"
con.Close()
Else
End If
End Sub