Wednesday, April 21, 2010

DataTable.Compute - filter parameters

The following code is to show most of the known feature of DataTable.Compute() method.

What this method do?

It computes the given expression on the current rows that pass the filter criteria.

object DataTable.Compute( string expression, string filter)

the function return "Object",so you can cast it to your data type as per the requirement.

The following aggregate types are supported in expression:

* Sum (Sum)
* Avg (Average)
* Min (Minimum)
* Max (Maximum)
* Count (Count)
* StDev (Statistical standard deviation)
* Var (Statistical variance)

Example,

int countFirstNameName = (int) dt.Compute("Count(FirstName)", "Name Like '" + txtFirstName.Text + "*'")

If the filter is not required, you must pass an empty string as the argument:

Like,
object sumObject = table.Compute("Sum(Amount)", "");

Here,
Amount is the Data tables Column name.

0 comments:

Post a Comment