How to delete selected row from Datagridview and Access DB in .NET
<p>I am trying to delete selected row from datagridview and commit changes permanently in my access DB here is my code:</p>

<pre><code>     cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" &amp; Application.StartupPath &amp; "\Accountcode.accdb;"
    cn.Open()

    Try
        For Each row As DataGridViewRow In DataGridView1.SelectedRows
            Using cn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" &amp; Application.StartupPath &amp; "\Accountcode.accdb;")
                Using cm As New OleDb.OleDbCommand
                    cm.Connection = cn
                    cm.CommandText = "DELETE * FROM CheckDJ WHERE [ID]= @id"
                    cm.CommandType = CommandType.Text
                    cm.Parameters.AddWithValue("@ID", CType(row.DataBoundItem, DataRowView).Row("ID"))
                    cm.ExecuteNonQuery()
                End Using
            End Using
        Next
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

    Try
        Using cn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" &amp; Application.StartupPath &amp; "\Accountcode.accdb;")
            Using cm As New OleDb.OleDbCommand
                strsql = "SELECT * FROM CheckDJ"
                cm.Connection = cn
                cm.CommandText = strsql
                cm.CommandType = CommandType.Text

                Dim da As New OleDbDataAdapter(strsql, cn)
                Dim ds As New DataSet()
                da.Fill(ds, "CheckDJ")
                DataGridView1.DataSource = ds.Tables(0)
            End Using
        End Using
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
</code></pre>

<p>But I'm having an error. <br> 
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Any help is very much appreciated. Thank you in advance!</p>