我试图通过datagridview删除我的数据库中的一条记录,只需按下delete键,但它给我错误“索引超出范围。必须是非负数并且小于集合的大小。”。这是我的代码
Private Sub DataGridView1_UserDeletedRow(sender As Object, e As DataGridViewRowEventArgs) Handles DataGridView1.UserDeletedRow
For i = 0 To DataGridView1.Rows.Count - 1
Dim deleterows As Integer = DataGridView1.SelectedRows(i).Cells(0).Value
Dim sqlquery As String = "delete from tblname where ID = " & deleterows & ";"
Dim sqlcommand As New OleDbCommand
With sqlcommand
.CommandText = sqlquery
.Connection = conn
.ExecuteNonQuery()
End With
Next
End Sub