DataTable.Compute Method
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Computes the given expression on the current rows that pass the filter criteria.
Namespace: System.Data
Assembly: System.Data (in System.Data.dll)
Parameters
- expression
- Type: System.String
The expression to compute.
- filter
- Type: System.String
The filter to limit the rows that evaluate in the expression.
Return Value
Type: System.ObjectAn Object, set to the result of the computation. If the expression evaluates to null, the return value will be Value.
The expression parameter requires an aggregate function. For example, the following is a legal expression:
Count(Quantity)
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 the Compute method would then be this:
Sum(total)
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.
Windows 8 Release Preview, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 SP2, Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.