here is my code for delete

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        If MsgBox("Are you sure you want to delete this item?", vbYesNo + vbQuestion, "Delete") = vbNo Then
            If Me.DataGridView1.Rows.Count > 0 Then
                If Me.DataGridView1.SelectedRows.Count > 0 Then
                    Dim x As Integer = Me.DataGridView1.SelectedRows(0).Cells("FNo").Value

                    If Not cnn.State = ConnectionState.Open Then
                    End If

                    'delete data
                    Dim cmb As New OleDb.OleDbCommand
                    cmb.Connection = cnn
                    cmb.CommandText = "DELETE FROM Food WHERE FNo=" & x


                    'refresh data

                    'close connection
                End If
            End If
        End If
    End Sub

it keep showing me error that Column named FNo cannot be found. in my access database, i have Fno as primary key, foodname and food price.

i dont think that line of code have problem. i think the problem come from this line of coding.

 Dim x As Integer = Me.DataGridView1.SelectedRows(0).Cells("FNo").Value

it looks like x cannot get the value from the selected row.

i found the the solution already. FNo is a reserve word in microsoft access database.thats why i cant get the value. just change the FNo to others name then problem solve.

This question has already been answered. Start a new discussion instead.