try this code for that
using System;
using System.Data;
public class DataTableComputeExample
{
public static void Main()
{
DataTable dtEmployee = new DataTable("Employee");
dtEmployee.Columns.Add("ID", typeof(int));
dtEmployee.Columns.Add("Name", typeof(string));
dtEmployee.Columns.Add("Salary", typeof(double));
dtEmployee.Rows.Add(52, "Human1", 21000);
dtEmployee.Rows.Add(63, "Human2", 22000);
dtEmployee.Rows.Add(72, "Human3", 23000);
dtEmployee.Rows.Add(110,"Human4", 24000);
Console.Write("Employee Count:");
Console.WriteLine(dtEmployee.Compute("Count(ID)", string.Empty));
Console.Write("Maximum Salary:");
Console.WriteLine(dtEmployee.Compute("Max(Salary)",string.Empty));
Console.Write("Minimum Salary:");
Console.WriteLine(dtEmployee.Compute("Min(Salary)", string.Empty));
Console.Write("Average Salary:");
Console.WriteLine(dtEmployee.Compute("Avg(Salary)", string.Empty));
Console.Write("Sum Salary:");
Console.WriteLine(dtEmployee.Compute("Sum(Salary)", string.Empty));
Console.ReadLine();
}
}
Output:
Employee Count:4
Maximum Salary:24000
Minimum Salary:21000
Average Salary:22500
Sum Salary:90000