I have a datagrid control with a list of names that it retrieves from a MySql database. I can search through them until i have one result. I want to be able to Display a groupbox control when the number of results is equal to 1. Also, in the groupbox i have a button that when clicked will delete this user from the server and their information from the mysql table called "employee". when the user is deleted i'll display a confirmation message in a messagebox, and reload the table with the updated list. so far the only two problems i have are showing the groupbox when the results are equal to 1 and deleting the user from the sql server based on the name of the search result. im using vb.net in visual basic 2010 express on windows 7 laptop. Thanks!
EDIT1:
Heres my code so far, please suggest how i can apply your answers to it. Thanks!
Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
'Search Function.
Dim sqlsearch1 As My开发者_高级运维SqlCommand = 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
for deleting, you can simply issue a delete statement and pass it a parameter, namely name.
DELETE FROM MyTable WHERE MyName = @Name
Im not sure what you need the group box for.
If you are doing something like
Set recBooks = con.Execute("SELECT * FROM Admin WHERE Name like 'hey' ;")
recbooks.count will return the number of records.
And for deleting, just run the query
DELETE FROM Admin WHERE Name = {0}
when the button is clicked, and reload the datagrid using datagrid.refresh()
精彩评论