vnewman29
asked on
Multiple select items in ListBox to SQL Database
I have two list boxes and I have written a statement to insert the selected item into the database, that work for single items. But I cannot get it to insert ALL selected items into the SQL database. Below is my VB.NET code. I am not getting an error and it is only inserting the first selected item.
For i = 0 To ListBox1.Items.Count - 1
If ListBox1.Items(i).Selected = True Then
'Data to be inserted
cmd.Parameters("@amenityid ").Value = Me.ListBox1.SelectedValue
cmd.Parameters("@locationi d").Value = Me.Request.QueryString("Lo cationID")
Dim ok As Integer = cmd.ExecuteNonQuery
MsgBox("Conference Room successfully updated.")
End If
Next i
For i = 0 To ListBox1.Items.Count - 1
If ListBox1.Items(i).Selected
'Data to be inserted
cmd.Parameters("@amenityid
cmd.Parameters("@locationi
Dim ok As Integer = cmd.ExecuteNonQuery
MsgBox("Conference Room successfully updated.")
End If
Next i
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER