Brad
Brad

Reputation: 21160

How do I implement a datatable "group by"?

I would like to implement a "Group By" for my datatable. Has any one any suggestions?

update:

c#, .net 2.0

Upvotes: 8

Views: 16553

Answers (2)

Lee
Lee

Reputation: 144136

You can use the linq extensions in the System.Data.DataSetExtensions assembly:

DataTable t = //
var groups = t.AsEnumerable()
    .GroupBy(r => r.Field<T>("columnName"))

Upvotes: 10

Richard
Richard

Reputation: 108995

Use LINQ to DataSets and the GroupBy extension methods.

Add assembly System.Data.DataSetExtensions.dll to your project to get access to the AsEnumerable() extension method.

Upvotes: 0

Related Questions