If you want to save the checked items of a list view, you can loop through them using
ListView.CheckedItems Property [
^]. That should make the code more robust.
So:
- prepare the SQL statement
- loop through the checked items
- on each iteration set the parameters correctly based on the item in hand
- execute the SQL statement (
INSERT
)
Few things to notice:
- use a transaction for the whole operation
- possibly delete all previously inserted data
- utilize proper error handling and roll back the transaction in case of an error
- never ever concatenate the values, use
SqlParameter
in your statements