Reputation:
I have a datatable with 4 columns
- 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();
Then because I want to iterate each of the linkCons I do the following, which only returns one datarow even though there is about 20 datarows for each linkCon. How do i return all the rows?
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
}
Upvotes: 2
Views: 1401
Reputation:
I had to change the code to where dr["LinkControl"].ToString() == linkC.linkCon.ToString()
and i dont really understand why.
Upvotes: 2