开发者

How to create an Ilist from DataTable with unknown columns

I have a DataTable that was built from dynamically created SQL, so I do not know the n开发者_运维知识库umber of columns in the datatable.

How can I convert this datatable into an IList?

EDIT: I am then going to use this to send to a Telerik Grid on the page.


To answer your edited question, you can simply bind the grid directly to the DataTable. (Or to its DefaultView)

You don't need a separate IList.


You can create an IList<Dictionary<string, object>> like this:

table.AsEnumerable()
     .Select(r => table.Columns.ToDictionary(c => c.ColumnName, c => r[c]))
     .ToList();


var list = new List<DataRow>();

foreach (var row in table.Rows)
   list.Add(row);

return list;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜