DataTable.Compute method

xiaoxiao2021-03-06  21

NET Framework class library

DataTable.Compute method

Calculate the given expression on the current line of the screening condition.

[Visual Basic]

Public Function Compute (_

Byval Expression As String, _

Byval filter as string_

AS Object

[C #]

Public Object Compute

String Expression,

String filter

);

[C ]

Public: Object * Compute

String * Expression,

String * filter

);

[Jscript]

Public Function Compute

Expression: String,

Filter: String

: Object;

parameter

EXPRESSION

The expression to be calculated.

Filter

To limit the filter for rows that perform in the expression.

return value

Object, set to the calculation result.

Note

The Expression parameter requires a polymeric function. For example, the following is a legal expression:

Count (Quantity)

However, the following expressions are illegal:

SUM (Quantity * Unitprice)

If you must perform actions for two columns or multiple columns, you should create DataColumn and set it to the appropriate expression, and then use the polymeric expression for the result column. In this case, it is assumed that there is a Datacolumn called "Total", and the expression property is set to:

"Quantity * Unitprice"

The expression parameters of the Compute method will be:

Sum (Total)

The second parameter FILTER determines which rows used in the expression. For example, if the table contains the date column named "Coldate", the following expressions can be limited:

Coldate> 1/1/99 and core <17/1/99

For rules for creating an expression for these two parameters, see the expression property of the Datacolumn class.

Example

[Visual Basic, C #, C ] The following example finds the value of the column named "total" for the salesperson of the identifier 5.

[Visual Basic]

Private subduteBysalesiSid (Byval MyDataSet As DataSet)

'PRESUMES A DATATABLE NAMED "Orders" That Has a Column name "Total."

DIM MyTable As DataTable

MyTable = myDataSet.tables ("Orders")

'Declare An Object Variable.

DIM OBJSUM As Object

Objsum = MyTable.Compute ("SUM (TOTAL)", "EMPID = 5")

End Sub

[C #]

Private void computebysalessalesid (DataSet myDataSet) {

// PRESUMES A DATATABLE NAMED "ORDERS" That Has A Column name "Total."

DataTable myTable;

myTable = mydataset.tables ["Orders"];

// Declare an Object variable.Object objsum

Objsum = MyTable.Compute ("SUM (Total", "Empid = 5");

}

[C ]

Private:

Void ComputeBysalesiSid (Dataset * MyDataSet) {

// PRESUMES A DATATABLE NAMED "ORDERS" That Has A Column name "Total."

DataTable * myTable;

MyTable = MyDataSet-> Tables-> Item [S "Orders"];

// Declare An Object Variable.

Object * Objsum;

Objsum = myTable-> Compute (S "SUM (TOTAL)", S "EMPID = 5");

}

[JScript] There is no example available for JScript. To view Visual Basic, C # or C examples, click the "Language Filter" button in the upper left corner.

Claim

Platform: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 Series, .NET Framework Lite

See

DataTable Class | DataTable Member | System.Data Name Space | Expression

转载请注明原文地址:https://www.9cbs.com/read-42836.html

New Post(0)