Hi...
I have a small proble while making program. I want to get maximum and minimum value of column say smarks of data table. How can I perform this task as it is prity simpple in sql query I just call max and min function. Is something like it present in ADO.NET.
Help me!
Thanks.
Anonymous User
23-Jul-2011Hi James,
You can do it by using compute method of DataTable.
DataTable dt = ds.Tables[0];
int min = dt.Compute("min(age)", string.Empty);
int max = dt.Compute(max(age)", string.Empty);
Hope this will solve your problem.
Anonymous User
23-Jul-2011Hi james,
You can use concept of Linq to solve your prtoblem.
Here I give you some code piece which might be solve your problem.
DataTable parentTable = ds.Tables[0];
List<int> values = parentTable.AsEnumerable().Select(age => age.Field<int>("sage")).Distinct().ToList();
string str = "Maximum Value : " + values.Max() + " : Minimum Value : " + values.Min();
MessageBox.Show(str);
Thanks.