本文转载自:http://www.cnblogs.com/sydeveloper/archive/2013/03/29/2988669.html 1.用两层循环计算,前提条件是数据已经按分组的列排好序的. DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn("name", typeof(string)), new DataColumn("sex",
操作Datatable group by 查询 //获取统计图形数据 var dicleft = new Dictionary<string, DataTable>(); ].AsEnumerable() group t by new { mname = t.Field<string>("COL_MATERIAL_NAME") } into m select new { MaterialName = m.Key.mname, value = m.ToList
通过linq查询datatable数据集合满足条件的数据集 1.首先定义查询字段的变量,比方深度 string strDepth=查询深度的值: var dataRows = from datarow in dataTable(须要查询的datatable数据集).AsEnumerable() where string.Compare(datarow.Field<string>(
using System.Web.Script.Serialization; using System.Collections.Generic; using System.Reflection; using System.Data; using System; namespace CommonCode { public class Common { /// <summary> /// LINQ返回DataTable类型 /// </summary> public static Da
LINQ查询表达式---------group子句 LINQ表达式必须以from子句开头,以select或group子句结束.使用guoup子句来返回元素分组后的结果.group 子句返回一个 IGrouping<TKey, TElement> 对象序列(实质上是列表的列表).TKey是键的对象类型,在用于group子句的时候,它一般用于存储分组的键值:TElement是指的对象类型,用于存储分组的结果. class Program { public class PerInfo { publi
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { internal class Program { private static void Main(string[] args) { DataTable dt = n
class ClientStruct { public string ID = "ID"; public string Name = "Name"; public string Company = "Company"; public string CreatedDate = "CreatedDate"; } " } }; protected void LinqDataTable() { DataRow row; Cl
对datatable 里面的数据按某一特定的栏位进行分组并且按照某一规则 var query = from t in rate.AsEnumerable() group t by new { t1 = t.Field<string>("Kind") } into m select new {Kind = m.Key.t1 }; if (query.ToList().Count > 0) { query.ToList().ForEach(q => { //根据
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 =