LINQ - Comma Seperated Value - Asked By harsh shah on 18-Jul-11 02:46 AM

Hi All,

below i have given a one example for getting comma seperated value. just F.Y


 var data2 = from d1 in dt.AsEnumerable()
            where d1.Field<int>("Fk_ID") == 0
            select new
           {
             id = d1.Field<int>("id"),
             Main = d1.Field<string>("Main"),
             Sub = string.Join(",", (from c in dt.AsEnumerable()
                           where c.Field<int>("Fk_ID") == d1.Field<int>("id")
                           select c.Field<string>("Main")).ToArray()),
           };

Check it

Regards,

Harsh Shah
Radhika roy replied to harsh shah on 18-Jul-11 01:18 PM
Using string.Join() function you can do this.

String.Join(sep, sArr);

Here you have to pass separator and array.

so first get the record and convert it to Array format, then pass that array in Join().


like this-

String.Join(",", your array);

Hope this will help you.