Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataTable Join all Rows Data

Actually,I have a DataTable containing 2000 rows with a ColumnName EMAIL. Now,I want to show all emails from the DataTable and adding them to a TextBox by separating with a ,.

I am achieving this by a for loop,But,it is taking a long time.

Actually,I have used for getting the ColumnNames :

string[] columnNames1 = (from dc in table.Columns.Cast<DataColumn>()
                                select dc.ColumnName).ToArray();

Is there any thing like this,for joining all rows data to a single string ?

like image 409
RealSteel Avatar asked Mar 23 '23 18:03

RealSteel


1 Answers

var text = string.Join(",", table.AsEnumerable()
                                 .Select(x=>x["EMAIL"].ToString())
                                 .ToArray());
like image 188
King King Avatar answered Apr 06 '23 09:04

King King