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
我在上面的代码中我从组合框中选择一个项目并使用datatable创建一个表并在datagrid中显示它。然后我点击删除按钮。该项目将从数据库中删除,但在此我想要在运行时从组合框中删除该项目。我已经在上面的代码中使用了两个查询用于选择,一个用于删除如果我用户加载方法它不起作用,因为连接已经打开错误来了。
答案 0 :(得分:1)
请参阅此网站 http://msdn.microsoft.com/en-us/library/19fc31ss.aspx
您可以使用功能RemoveItem
YourCombo.RemoveItem(index)
或清除YourCombo.Clear()
的组合并重新加载