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
        Else
            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
                        cnn.Open()
                    End If

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

                    cmb.ExecuteNonQuery()

                    'refresh data
                    Me.RefreshData()

                    'close connection
                    cnn.Close()
                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 don't know much about access but try

cmb.CommandText = "DELETE * FROM Food WHERE FNo=" & x

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.