How to covert column values of a datatable to string array or string
Sometimes we need the column values of a datatable as string array.Most of the programmer follows the looping through the rows of datatable and append it to string or stringbuilder.But we can do it by a single statement with avoiding the looping.
string[] emCodesprmFocus = Array.ConvertAll(dtAllEm.Select(),row => (String)row["NAME"].ToString());
Note :dtAllEm is the datatable and NAME is the column.
If you want to convert the string array to string with "," as separator then
string names = String.Join(",", emCodesprmFocus);
coooollllllllllllllllll
ReplyDelete