I am using asp.net with vb.net. I have created 2 listboxes; lstselect and lstroles. List boxes lstselect contains all of the available roles that can be added into lstroles. How do I take the roles that have been added into lstroles and make them into a parameter to pulled into my database when the stored procedure runs?
Here is the code for how my list boxes share the roles:
Protected Sub btnRight_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRight.Click
If lstselect.SelectedIndex <> -1 Then
lstroles.Items.Add(lstselect.SelectedItem.Text)
lstselect.Items.Remove(lstselect.SelectedItem.Text)
End If
End Sub
Protected Sub btnLeft_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLeft.Click
If lstroles.SelectedIndex <> -1 Then
lstselect.Items.Add(lstroles.SelectedItem.Text)
lstroles.Items.Remove(lstroles.SelectedItem.Text)
End If
End Sub
Thanks!
There are two ways to do it:
1) Create a Comma Separated Values from Your List Box Selected Items. But this is not a recommended Approach, as you need to parse it in your Stored Procedure.
2) Create an XML, each Role would be a Node. And Pass XML as your Stored Procedure Parameter. Most Databases Support Easily retrieving Data from XML. btw, Which Database are you using?
3) If you are using MS SQL 2008, you can also use
Table-Valued Parameters: http://msdn.microsoft.com/en-us/library/bb510489.aspxbut its only recommended for Bulk Insert kind of operations. The Recommended approach for you is XML, i would say.