Use LINQ. It works fine on datatables if you convert a collection of strings to IEnumerable.
List<int> levels = AccountTable.AsEnumerable().Select(al => al.Field<int>("AccountLevel")).Distinct().ToList(); int min = levels.Min(); int max = levels.Max();
Edited to correct syntax; this is difficult when using LINQ in DataTables, as well as aggregation functions too.
Yes, this can be done with a single query, but you will need to generate a list of results, and then use .Min () and .Max () as aggregating functions in separate statements.
Cylon Cat Mar 14 '10 at 15:16 2010-03-14 15:16
source share