Stings and LINQ

Hello people ,

i have small requirement ,to concatinate a datable using linq into a string or list

input datatable

cloumnA columnB columnC
a p x
b q y
c r z

i need output as below inside brackets
—{ when c1=a and c2=p then ‘x’ when c1=b and c2=q then ‘y’ when c1=c and c2=r then ‘z’ } and so on

thanks in advance

Hi,

How about the following?

String.Join(" ",dt.AsEnumerable.Select(Function(r)  "when c1="+r("ColumnA").ToString+" and c2="+r("ColumnB").ToString+" then ‘"+r("ColumnC").ToString+"’"  ))

Regards,

1 Like

it is saying AsEnumerable is not a member of syste.data.datable

Do you want LINQ only or any other solution would work.

any other is also okay, i just need to have those multiple row into single string so i can perform update activity on db

Hey guys ,
thanks for the replies
String.Join(“,”,Datatable.AsEnumerable().Select(Function(a) “(“+String.Join(“,“,a.ItemArray())+”)”).ToArray())
i adapted the above solution as per my requirement , i got the required output

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.