Reputation: 61
How do i update items in the ListView at the same time in my database? I have this code but i don't know what's wrong, It only updates the first row in the Listview. I want to update all the items that is shown in the listview
For Each row As ListViewItem In ListView3.Items
con.Open()
cmd.Connection = con
cmd.CommandText = "update pawn set status = 'Redeemed' where pawn_id = '" & ListView3.Items(0).Text & "'"
dr = cmd.ExecuteReader
con.Close()
Next
Upvotes: 1
Views: 661
Reputation: 3890
You are always sending 0th element of listview in parameter.
Here is error:
cmd.CommandText = "update pawn set status = 'Redeemed' where pawn_id = '" & ListView3.Items(0).Text & "'"
There should be:
cmd.CommandText = "update pawn set status = 'Redeemed' where pawn_id = '" & row.Text & "'"
If You always send ListView3.Items(0).Text
in WHERE statement - it always updates same row.
Upvotes: 1