Monday, 22 July 2013

Convert Dataset to List Using Linq



public void test()
{
   DataSet ds = new DataSet();
   ds.Tables[0].Rows.Cast<System.Data.DataRow>().Select(p => new TestList()
   {
     Name = p["Resource_Number"].ToString(),
     City = p["ConnectionId"].ToString(),
     Class = p["ConnectionId"].ToString()
   }).ToList();
}

public class TestList
{
  public string Name { get; set; }
  public string City { get; set; }
  public string Class { get; set; }
}

No comments:

Post a comment