使用DataGridView中的ID删除命令

问题描述 投票:0回答:2

我的数据显示在DataGridView中。在下面的代码运行的网格中选择ID时,我做了一个Button,但我一直收到错误消息。

Dim cnx As New MySqlConnection("datasource=localhost;database=bdgeststock;username=root;password=")
Dim cmd As MySqlCommand = cnx.CreateCommand
Dim resultat As Integer
If ConnectionState.Open Then
    cnx.Close()
End If
cnx.Open()
If grid.SelectedCells.Count = 0 Then
    MessageBox.Show("please select the ids that u want to delete")
Else
    cmd.CommandText = "delete from utilisateur where idu= @P1"
    cmd.Parameters.AddWithValue("@P1", grid.SelectedCells)
    resultat = cmd.ExecuteNonQuery
    If (resultat = 0) Then
        MessageBox.Show("error")
    Else
        MessageBox.Show("success")
    End If
End If
cnx.Close()
cmd.Dispose()
mysql database vb.net winforms sql-delete
2个回答

0
投票
这有什么意义?
© www.soinside.com 2019 - 2024. All rights reserved.