Compute
Objectobj
= DataTable.Compute(Stringexpression
, Stringfilter
);
Returns the result of an aggregate expression for a subset of rows in the table meeting the filter criteria.
obj
Returns an object containing the results computed.
expression
The expression to calculate.
filter
A filter that identifies a subset of rows for which the expression is computed.
The following example demonstrates how to use the Compute( )
method to calculate the sum of a column for a subset of
the rows filtered from the table:
DataTable dt = new DataTable(); dt.Columns.Add("OrderId", typeof(System.Int32)); dt.Columns.Add("OrderAmount", typeof(System.Decimal)); // ... add some rows // computes the sum of order amounts for all orders with Id less than 10 Decimal totalOrderAmount= (Decimal) dt.Compute("SUM(OrderAmount)", "OrderId<10");