j c

j c

  • NA
  • 45
  • 0

generate dynamic string

Dec 13 2010 1:30 PM

I have a sp that generates a result looks like below
  
 Userid    orgid
 
1                 100
1                 200
1                 400
2                 100
 
I would like to generate a string something like below by looping thru the output result data table using ado.net
 
Userid 1 should generate
 
It needs to generate below statement surround by {} and separated by comma(,) if it has multiple orgids.. and orgid( after & ) need to be dynamically assigned in the string based on the table..
 
{[Org].[org ID].&[100], [Org].[org ID].&[200] ,[Org].[org ID].&[400] }
 
 
 
Userid =2
 
{[Org].[org ID].&[100] }
 
 
How can I dynamically generate this statement?
 I can generate the stament if there is only one orgid for user but if you have multiple orgs .. not sure how Ic an concatenate multiple orgids by comma..

AllowedSet =
"{[org].[org ID].&[" + orgID + "]}";

 
I am using  C#

Answers (12)