HEEN
HEEN

Reputation: 4727

Convert datatable column values in a comma separated string in c#

I have a datatable who has only one column with values as below

    COLUMN1

      a

      b

      c

      d

So what I want is, I want this values in a string with comma separated like below

string value = a,b,c,d

How will I get this.

Upvotes: 3

Views: 11428

Answers (1)

Oskar
Oskar

Reputation: 202

var list = dt.AsEnumerable().Select(r => r["COLUMN1"].ToString());
string value = string.Join(",", list);

Upvotes: 11

Related Questions