Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

Build comma seperated string from datatable

I have a datatable in VB code called dtSpecialty

It has 3 columns
ID  string value
Name string value
EmailBlastDefault Boolean value

I need to build a comma seperated string that cycles through the table rows and where EmailBlastDefault = 1 (True) add name to string called liThisSpecialty

So I can use the resulting string (liThisSpecialty)  to run this

        For Each liThisSpecialty In cblSpecialties.Items
            If InStr(sSpecialtiesToSkip, "," & liThisSpecialty.Text & ",") > 0 Then
            Else
                liThisSpecialty.Selected = True
            End If
        Next
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Can you show a sample of rows in this table?
Avatar of Larry Brister

ASKER

Code Cruiser

Sure

ID             Name               EmailBlastDefault
ANTE         Antepartum          1
BIOMED   BIOMEDTECH      0
BMET        BMET                       1

Would build this string
,Antepartum,BMET ,
ASKER CERTIFIED SOLUTION
Avatar of Paul_Harris_Fusion
Paul_Harris_Fusion
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hey guys,
 Worked it out myself...
This is final solution...does anyone feel like they have points coming to them?


    Sub BindChoices()
        Dim dtSpecialty As New DataTable
        dtSpecialty = GetSpecialty()
        BindToDatasource(cblSpecialties, dtSpecialty, "Name", "ID")

        Dim liThisSpecialty As ListItem
        Dim sSpecialtiesToSkip As String = ","

        For Each row As DataRow In dtSpecialty.Rows
            If row.Item("EmailBlastDefault") = "0" Then
                sSpecialtiesToSkip = sSpecialtiesToSkip & row.Item("Name") & ","
            End If
        Next row

        For Each liThisSpecialty In cblSpecialties.Items
            If InStr(sSpecialtiesToSkip, "," & liThisSpecialty.Text & ",") > 0 Then
            Else
                liThisSpecialty.Selected = True
            End If
        Next
    End Sub

Open in new window

That's up to you to decide.
Gave me a great start