gpt4 book ai didi

mysql - 从数据库中删除后,如何在运行时从组合框中删除项目

转载 作者:行者123 更新时间:2023-11-29 14:23:05 25 4
gpt4 key购买 nike

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

在上面的代码中,我从组合框中选择一个项目并使用数据表创建一个表并将其显示在数据网格中。然后我点击删除按钮。该项目正在从数据库中删除,但在这里我想在运行时从组合框中删除该项目。我已经在上面的代码中使用了两个查询,一个用于选择,一个用于删除,如果我用户加载方法它不起作用,因为连接已打开错误出现。

最佳答案

引用这个网站 http://msdn.microsoft.com/en-us/library/19fc31ss.aspx

您可以使用函数RemoveItem

YourCombo.RemoveItem(index)

或使用 YourCombo.Clear() 清除组合并再次加载

关于mysql - 从数据库中删除后,如何在运行时从组合框中删除项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11448859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com