LINQ query on a DataTable

前端 未结 23 1390
执笔经年
执笔经年 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:25

                        //Json Formating code
                        //DT is DataTable
                        var filter = (from r1 in DT.AsEnumerable()
    
                                      //Grouping by multiple columns 
                                      group r1 by new
                                      {
                                          EMPID = r1.Field("EMPID"),
                                          EMPNAME = r1.Field("EMPNAME"),
    
                                      } into g
                                      //Selecting as new type
                                      select new
                                      {
    
                                          EMPID = g.Key.EMPID,
                                          MiddleName = g.Key.EMPNAME});
    

提交回复
热议问题