---
title: "How to get max and min value of columns in data table?"  
description: "How to get max and min value of columns in data table?"  
author: "James Smith"  
published: 2011-07-23  
updated: 2011-07-23  
canonical: https://www.mindstick.com/forum/275/how-to-get-max-and-min-value-of-columns-in-data-table  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How to get max and min value of columns in data table?

Hi...

I have a small proble while making program. I want to get maximum and minimum [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) of [column](https://www.mindstick.com/forum/33860/how-to-calculate-column-summary-in-sql-server) [say](https://answers.mindstick.com/qa/116645/a1-wreckers-reviews-what-do-customers-say) smarks of [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) table. How can I perform this [task](https://www.mindstick.com/forum/161761/what-is-the-difference-between-task-and-thread) as it is prity simpple in [sql query](https://www.mindstick.com/forum/529/rename-table-name-and-column-name-using-sql-query) I just call [max](https://www.mindstick.com/articles/1155/count-max-min-function-in-excel) and min function. Is something like it [present](https://answers.mindstick.com/qa/96635/explain-about-the-various-features-present-in-ms-access) in ADO.NET.

Help me!

Thanks.

## Replies

### Reply by Anonymous User

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.

### Reply by Anonymous User

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.


---

Original Source: https://www.mindstick.com/forum/275/how-to-get-max-and-min-value-of-columns-in-data-table

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
