我无法从我的datagridview中删除记录,因为每次尝试删除记录时都会抛出错误。错误显示“没有给出一个或多个所需参数的值”。 这是我的代码:
Private Sub delete_Click(sender As Object, e As EventArgs) Handles delete.Click
If Me.DataGridView1.Rows.Count > 0 Then
If Me.DataGridView1.SelectedRows.Count > 0 Then
Dim myPrimaryKey As Integer = Me.DataGridView1.SelectedRows(0).Cells("id").Value
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
Dim cmd As New OleDb.OleDbCommand
cmd.Connection = cnn
'cmd.CommandText = "DELETE * FROM attendance " & intemployeeno
cmd.CommandText = "DELETE FROM VehicleDefects WHERE id=" & myPrimaryKey
cmd.ExecuteNonQuery()
Me.refreshdata()
Else
MessageBox.Show("Select 1 row before you hit Delete")
cnn.Close()
End If
End If
End Sub
答案 0 :(得分:0)
尝试这样
cmd.CommandText = "DELETE FROM VehicleDefects WHERE id='" & myPrimaryKey & "'"
答案 1 :(得分:0)
我认为你可能在Me.refreshdata()
上遇到问题向我们展示refreshdata()子程序/功能
的代码答案 2 :(得分:0)
很多时候"no value given for one or more required paramemters".
此错误是由于无效的列名称造成的。我建议请检查cmd.CommandText = "DELETE FROM VehicleDefects WHERE id=" & myPrimaryKey
行