1

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
Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
  • SideNote: [How do I create a parameterized SQL query? Why Should I?](http://stackoverflow.com/questions/542510/how-do-i-create-a-parameterized-sql-query-why-should-i) – Vivek S. Feb 08 '16 at 07:28

1 Answers1

1

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.

akhil kumar
  • 1,598
  • 1
  • 13
  • 26
madoxdev
  • 3,770
  • 1
  • 24
  • 39