有时候我们从数据库中查询出来数据之后,需要按照DataTable的某列进行分组,可以使用下面的方法实现,代码如下: using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DataTableGroupDemo { class Program { static voi…
DataTable dt = GetTestData(10); //获取10条测试数据 var queryByService = from r in dt.AsEnumerable() group r by r.Field<string>(4) into g select new { Service = g.Key, Bookings = g.Count(p => p.Field<string>(1) !=""), ConfirmedBookings =…
1.数据分组求合,分别用的实体类以及datatable来分组求合,还有分组求和之后的如何取值 //实体类版本 List<ProgramTimeModel> TotalAllList = GetData(); var a = from p in TotalAllList.AsEnumerable() group p by p.ProgramTime_ID into g select new ProgramTimeModel { ProgramTime_ID = g.Key, Saled = g.…
DataTable分组统计: .用两层循环计算,前提条件是数据已经按分组的列排好序的. DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn("name", typeof(string)), new DataColumn("sex", typeof(string)), new DataColumn("score", typeof(…