8

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

update:

c#, .net 2.0

Brad
  • 20,302
  • 36
  • 84
  • 102
  • http://stackoverflow.com/questions/499578/c-linq-query-group-by should answer your question, or you could look here: http://msdn.microsoft.com/en-us/vcsharp/aa336754.aspx#simple1 – Webleeuw Nov 17 '09 at 17:10

2 Answers2

10

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

DataTable t = //
var groups = t.AsEnumerable()
    .GroupBy(r => r.Field<T>("columnName"))
Lee
  • 142,018
  • 20
  • 234
  • 287
0

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.

Richard
  • 106,783
  • 21
  • 203
  • 265