Reputation: 1
Private Sub btn_remove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_remove.Click
Dim Query As String
Dim query1 As String
Dim i As Integer = 0
i = DataGridView1.CurrentRow.Index
Dim strValueYouWant As String = String.Empty
strValueYouWant = DataGridView1.Item(0, i).Value
Dim result1 As DialogResult = MessageBox.Show("Are you sure,you want delete the selected row?", _
"Important Question", MessageBoxButtons.YesNo)
If result1 = DialogResult.Yes Then
mysqlconn.Open()
Query = "delete from table1 where show_id= '" & strValueYouWant & "'"
Dim cmd As MySqlCommand = New MySqlCommand(Query, mysqlconn)
Dim k As Integer = cmd.ExecuteNonQuery()
Query = Nothing
cmd.Dispose()
query1 = "select * from table1"
Dim cmd1 As New MySqlCommand(query1, mysqlconn)
Dim reader As MySqlDataReader = cmd1.ExecuteReader
Dim table As New DataTable()
table.Load(reader)
DataGridView1.DataSource = table
query1 = Nothing
ElseIf result1 = DialogResult.No Then
Exit Sub
End If
mysqlconn.Close()
End Sub
I above code I select an item from combobox and create a table using datatable and display it in datagrid. Then I click on remove button. The item is getting deleted from the database but here I want delete that item from combobox as well during run time. I am already using two queries in above code one for selecting and one for deleting if I user loading method it does not work because connection is already open error comes.
Upvotes: 0
Views: 350
Reputation: 6147
Refer this site http://msdn.microsoft.com/en-us/library/19fc31ss.aspx
You can use function RemoveItem
YourCombo.RemoveItem(index)
or clear the combo with YourCombo.Clear()
and load it again
Upvotes: 1