Monday, July 18, 2011

Get all column names of datatable into string array



using Linq you can easily get list/array of all column names of a datatable:

string[] columnNames = dt.Columns.Cast< datacolumn > ().Select(x => x.ColumnName).ToArray();
//or in LINQ
string[] columnNames = (from dc in dt.Columns.Cast< datacolumn >() select dc.ColumnName).ToArray();


Compiled By: Rajesh Rolen

Share This!


No comments:

Powered By Blogger · Designed By Seo Blogger Templates