Question : Getting the data from a comma delimited string using SQL Query

I need to loop thru and query the database to optain the users email address...
this function obtains the delimited string (csv)
I need help on the code structure...
-----------------------------------------------------------
     Shared sb As New StringBuilder
     Protected Sub grdAttendees_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
         
         If e.Item.ItemType = ListItemType.Item Then
             If Not sb.ToString().Contains(e.Item.Cells(0).Text) Then
                 sb.Append(e.Item.Cells(0).Text)
                 sb.Append(",")
             End If
         End If

         Dim strKeywordID As String = sb.ToString()
         Session("sbEmailAddressID") = strKeywordID
 End Sub
------------------------------------------------------------
the 'strKeywordID' string is like: 154,154,155,156,
I pass this to another file using -> Session("sbEmailAddressID")
-----------------------------------------------------------------------------------
In this file I need to know how to parse session var sb
 Dim sb As String = Session("sbEmailAddress")

Parse or split sb(",") ... and create a for loop based on the count of 'ID' .... the name of items in the string ... and then loop thru and query the sql/server database
For loop?
SELECT strBadgeName FROM  i2Integration_EventRegv45_RegistrationUser where intRegistrationUserID = @ID
next
---------------------------------------------------------------------------------

Answer : Getting the data from a comma delimited string using SQL Query

try this
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Dim strEmailAddress As String = ""
            Dim dtVolumeOrder As New DataTable()
            Dim length As Integer = Convert.ToString(Session("sbEmailAddress")).Split(",").Length
            Dim ids As String() = New String(length - 1) {}
            For i As Integer = 0 To length - 1

                Dim strSelectCommand As String = "  SELECT strBadgeName(i) FROM  i2Integration_EventRegv45_RegistrationUser where intRegistrationUserID = " + ids[i]
                Using sqlConn As New SqlConnection(ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString)
                    Using adapPatientBills As New SqlDataAdapter(strSelectCommand, sqlConn)
                        adapPatientBills.Fill(dtVolumeOrder)
                    End Using
                End Using

                strEmailAddress = strEmailAddress + strSelectCommand + "," ' build string of email addresses seperated by ','
            Next
Random Solutions  
 
programming4us programming4us