I’m working with Windows Forms – VB.NET.
Here’s what I have:
- A
ListViewwith checkboxes set toTrue - A
Button(triggers the update) - A database table with similar fields as the
ListView
What I want to happen:
- when the user clicks the
Button, all items on theListViewwith checkbox checked will be updated.
My progress:
- I’ve already collected the
IDof the checked items and stored them in an array. I’ll be using this to update the database table.
The problem:
- I don’t know how to put them in the
SqlCommand.Parameters - Also, I don’t know the update command for such scenario (where in/exist (@parameters))
Thanks in advance!
If you’re using SQL Server 2008 or later, you can use table-valued parameters. These let you continue to deal with the separate IDs on separate rows, perform SQL joins, etc. There are plenty of examples on the page I’ve linked to, e.g.:
You could easily replace that
INSERTwith anUPDATE, as shown earlier on the page:And adjust parameter names accordingly.