I have inventory received table in access database where productID is repeated many time. I can populate this data in listview. Currently, when i select any row in listview and press delete button, all entries of the selected product id is deleted from the listview as well as from datbase from the beginning up to end. What i want is if i select any item in listview and press delete button, only selected row should be deleted form listview and from database not all even if it is same productid. Please help me if someone can?? Please see the code below.
Private Sub Button9_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button9.Click
Dim item1 As ListViewItem
item1 = ListView1.SelectedItems(0)
Dim Del As DialogResult
Del = MessageBox.Show("Are you sure you want to delete the record", "Delete Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Del = DialogResult.Yes Then
'Dim item As ListViewItem
con.Open()
Dim sql As String = "DELETE FROM Receipt WHERE ProductID='" & item1.SubItems(0).Text & "'"
With cmd
.CommandText = sql
.Connection = con
.ExecuteNonQuery()
End With
MsgBox("Record Removed", MsgBoxStyle.Information)
End If
con.Close()
End Sub