标题:c#datatable分组查询怎样做
只看楼主
lzkpjm
Rank: 1
等 级:新手上路
威 望:1
帖 子:3
专家分:0
注 册:2014-2-6
 问题点数:0 回复次数:0 
c#datatable分组查询怎样做
  DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[] { new DataColumn("unit", typeof(string)),
                                         new DataColumn("workarea", typeof(string)),
                                         new DataColumn("level", typeof(string)),
                                         new DataColumn("num",typeof(int))});
            dt.Rows.Add(new object[] { "山东省", "济南市", "历下区", 20 });
            dt.Rows.Add(new object[] { "山东省", "济南市", "历下区", 10 });
            dt.Rows.Add(new object[] { "山东省", "济南市", "历下区", 30 });

            dt.Rows.Add(new object[] { "山东省", "泰安市", "市中区", 40 });
            dt.Rows.Add(new object[] { "山东省", "泰安市", "市中区", 15 });

            dt.Rows.Add(new object[] { "山东省", "泰安市", "泰山区", 40 });
            dt.Rows.Add(new object[] { "山东省", "泰安市", "泰山区", 15 });

            dt.Rows.Add(new object[] { "辽宁省", "沈阳市", "和平区", 20 });
            dt.Rows.Add(new object[] { "辽宁省", "沈阳市", "和平区", 12 });

            dt.Rows.Add(new object[] { "辽宁省", "沈阳市", "沈河区", 25 });
            dt.Rows.Add(new object[] { "辽宁省", "沈阳市", "沈河区", 30 });

            dt.Rows.Add(new object[] { "辽宁省", "鞍山市", "铁东区", 10 });
            dt.Rows.Add(new object[] { "辽宁省", "鞍山市", "铁东区", 25 });

以上是表的内容
要求按照,省、市、区分组查询num的和并添加小计、合计、总计,具体应该怎样写代码。谢谢

[此贴子已经被作者于2021-9-25 19:55编辑过]

搜索更多相关主题的帖子: object Rows Add new datatable 
2021-09-25 19:54



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-506977-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.055857 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved