Friday, January 21, 2011

How to convert DataTable into anonymous type class list for LINQ

System.Data.DataTable table = dataSet.Tables[0];
var GridviewData = from oneRow in table.AsEnumerable()
  select new
  {
  ID = oneRow.Field<Int32>("ID"),
  Amount = oneRow.Field<decimal>("Amount"),
  Description = oneRow.Field<string>("Description"),
  DateTime = oneRow.Field<System.DateTime?>("DateTime"),
  };

2 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete