我有一个包含4列的数据表
- A|1|Apple|Turnip - A|2|Water|Fruit - B|1|Water|Orange - B|2|Water|Mango - C|1|Hello|World
What I want to do is select distinct column A. Then I want to select distinct columns 2,3,4 based on column A.
This is what i'm using to select distinct column A. My question with this first part is how do you order by column A (linkControl). Member is my datatable, and this returns every distrinct column a
var linkControl = Member.AsEnumerable()
.Select(row => new
{
linkCon = row.Field<string>("LinkControl")
})
.Distinct();
然后,因为我要遍历每个linkCons,所以我执行以下操作,即使每个linkCon大约有20个数据行,它也只返回一个数据行。如何返回所有行?
foreach (var linkC in linkControl)
{
var linkControllink = (from DataRow dr in ADMemberships.Rows
where dr["LinkControl"] == linkC.linkCon
orderby (string)dr["URLDescription"]
select dr);
}
foreach (var lcl in linkControllink)
{
//only has one row in it
}
最佳答案
我不得不将代码更改为where dr["LinkControl"].ToString() == linkC.linkCon.ToString()
,我真的不明白为什么。