DataTable.Compute Method (String, String)
Computes the given expression on the current rows that pass the filter criteria.
Assembly: System.Data (in System.Data.dll)
The expression to compute.
The filter to limit the rows that evaluate in the expression.
The expression parameter requires an aggregate function. For example, the following is a legal expression:
But this expression is not:
Sum (Quantity * UnitPrice)
If you must perform an operation on two or more columns, you should create a DataColumn, set its Expression property to an appropriate expression, and use an aggregate expression on the resulting column. In that case, given a DataColumn with the name "total", and the Expression property set to this:
"Quantity * UnitPrice"
The expression argument for themethod would then be this:
The second parameter, filter, determines which rows are used in the expression. For example, if the table contains a date column named "colDate", you could limit the rows with the following expression:
colDate > 1/1/99 AND colDate < 17/1/99
For rules on creating expressions for both parameters, see the DataColumn.Expression property.
The following example sums the values of a column named "Total", for the salesperson whose identification number is five.
Available since 1.1