Wednesday, October 24, 2012

Get the Sum of a Particular DataTable Column

Use the DataTable.Compute method


    DataTable table;
table = dataSet.Tables["Orders"];

// Declare an object variable. 
object sumObject;
sumObject = table.Compute("Sum(Total)", "EmpID = 5");
where "EmpID = 5" is a filter expression. 

Use empty string if filter expression is not needed.

No comments:

Post a Comment