user3460287 February 2016

VB.net MySQL Update all items in the listview

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

Answers


Kamil Stachowiak February 2016

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.

Post Status

Asked in February 2016
Viewed 2,073 times
Voted 7
Answered 1 times

Search




Leave an answer