LINQ query on a DataTable

前端 未结 23 1677
执笔经年
执笔经年 2020-11-22 01:59

I\'m trying to perform a LINQ query on a DataTable object and bizarrely I am finding that performing such queries on DataTables is not straightforward. For example:

23条回答
  •  孤独总比滥情好
    2020-11-22 02:04

    Example on how to achieve this provided below:

    DataSet dataSet = new DataSet(); //Create a dataset
    dataSet = _DataEntryDataLayer.ReadResults(); //Call to the dataLayer to return the data
    
    //LINQ query on a DataTable
    var dataList = dataSet.Tables["DataTable"]
                  .AsEnumerable()
                  .Select(i => new
                  {
                     ID = i["ID"],
                     Name = i["Name"]
                   }).ToList();
    

提交回复
热议问题