Larry Brister
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
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
Can you show a sample of rows in this table?
ASKER
Code Cruiser
Sure
ID Name EmailBlastDefault
ANTE Antepartum 1
BIOMED BIOMEDTECH 0
BMET BMET 1
Would build this string
,Antepartum,BMET ,
Sure
ID Name EmailBlastDefault
ANTE Antepartum 1
BIOMED BIOMEDTECH 0
BMET BMET 1
Would build this string
,Antepartum,BMET ,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hey guys,
Worked it out myself...
This is final solution...does anyone feel like they have points coming to them?
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
That's up to you to decide.
ASKER
Gave me a great start