Sponsored By
DataConverter
Advertise with Us
Advertisement
Advertise with Us
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog
Report Abuse Form
Reason:    
   

Home >> .Net >> C# >> How to get max and min value of columns in data table?
Author Post

James Smith


Total Post: 48
Member Since: 3/16/2011
Points: 270
How to get max and min value of columns in data table?
Posted On: 7/23/2011 4:42:50 AM

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.

Author Post

Awadhendra Tiwari


Total Post: 126
Member Since: 1/19/2011
Points: 893
Re: How to get max and min value of columns in data table?
Posted On: 7/23/2011 5:47:05 AM

Hi 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.

Author Post

Haider M Rizvi


Total Post: 40
Member Since: 6/6/2010
Points: 291
Re: How to get max and min value of columns in data table?
Posted On: 7/23/2011 12:54:45 PM

Hi 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.

Report Abuse Form
Reason:    
 
Total Online Users: 2819
Advertisement
MindStick DataConverter
Advertise with Us
  
Copyright © 2009 - 2013MindStick. All Rights Reserved.