C# 过滤数据表的最佳方式是什么?
在我的一个c#需求中,我有一个datatable,其中包含以下数据C# 过滤数据表的最佳方式是什么?,c#,linq,datatable,C#,Linq,Datatable,在我的一个c#需求中,我有一个datatable,其中包含以下数据 Category Topics Resourceworked A tp1 Hemant A tp2 Kevin B tp3 Haris B tp4 Hemant B tp5 Hemant C tp6 Kevin 在输出中,我需要两组数据 输出-1:对于每个独特的类别,有多少资源起作用 Category N
Category Topics Resourceworked
A tp1 Hemant
A tp2 Kevin
B tp3 Haris
B tp4 Hemant
B tp5 Hemant
C tp6 Kevin
在输出中,我需要两组数据
输出-1:对于每个独特的类别,有多少资源起作用
Category NoOfResorces
A 2
B 2
C 1
输出-2:resorces为不安静类别(如)工作了多少次
Category Resource NoOfTime
A Hemant 1
A Kevin 1
B Haris 1
B Hemant 2
C Kevin 1
实现输出(即数据表过滤器或LINQ)的最佳方法是什么
补充:
任何LINQ专家都能告诉我学习LINQ的好的在线网站或书籍吗?以下是您的第一个要求:
var uniqueCat = from d in tblData.AsEnumerable()
group d by (string)d["Category"] into Group
select Group;
var catRes = from grp in uniqueCat
let c = grp.Select(r => r["Resourceworked"]).Distinct().Count()
select new {Category = grp.Key, NoOfResorces=c};
var summary = from cr in catRes
select string.Format("Category:{0} Count:{1}",cr.Category,cr.NoOfResorces);
MessageBox.Show(string.Join(Environment.NewLine,summary));
这是第二个查询:
var uniqueCatRes = from d in tblData.AsEnumerable()
group d by new{Cat= d["Category"], Res=d["Resourceworked"]} into Group
select Group;
var catResCount = from grp in uniqueCatRes
let Category = grp.Key.Cat
let Resource = grp.Key.Res
let NoOfResorces = grp.Count()
select new { Category,Resource,NoOfResorces };
summary = from crc in catResCount
select string.Format("Category:{0} Resource:{1} Count:{2}", crc.Category,crc.Resource, crc.NoOfResorces);
MessageBox.Show(string.Join(Environment.NewLine,summary));
这是您的第一个要求:
var uniqueCat = from d in tblData.AsEnumerable()
group d by (string)d["Category"] into Group
select Group;
var catRes = from grp in uniqueCat
let c = grp.Select(r => r["Resourceworked"]).Distinct().Count()
select new {Category = grp.Key, NoOfResorces=c};
var summary = from cr in catRes
select string.Format("Category:{0} Count:{1}",cr.Category,cr.NoOfResorces);
MessageBox.Show(string.Join(Environment.NewLine,summary));
这是第二个查询:
var uniqueCatRes = from d in tblData.AsEnumerable()
group d by new{Cat= d["Category"], Res=d["Resourceworked"]} into Group
select Group;
var catResCount = from grp in uniqueCatRes
let Category = grp.Key.Cat
let Resource = grp.Key.Res
let NoOfResorces = grp.Count()
select new { Category,Resource,NoOfResorces };
summary = from crc in catResCount
select string.Format("Category:{0} Resource:{1} Count:{2}", crc.Category,crc.Resource, crc.NoOfResorces);
MessageBox.Show(string.Join(Environment.NewLine,summary));
是否可以将摘要转换为数据表?我收到一些类型转换错误。是否可以将摘要转换为数据表?我收到一些打字错误。