Function expression () can be used in DataTable.Select

Expression a usage attribute is calculated to create columns. For example, to calculate the value of the tax, the tax rate will be multiplied by the unit price for a given region. Due to the different rates throughout, a single rate is not possible to put the column; then they use Expression attribute value is calculated as shown in the following Visual Basic code:

DataSet1.Tables("Products").Columns("tax").Expression = "UnitPrice * 0.086"

The second purpose is to create the aggregate column. Similar to the calculated value, based on the polymerization DataTable perform operations set in the entire row. A simple example is to return to the number of rows to count, which is what you might be used to counting method for a particular salesperson to complete the number of transactions, as shown in the following Visual Basic code:

DataSet1.Tables("Orders").Columns("OrderCount").Expression = "Count(OrderID)"

 

Expression syntax

When you create expressions, use the ColumnName property to refer to columns. For example, if a column ColumnName is "UnitPrice" (unit price), and the other is the "Quantity" (number), expression will be:

"UnitPrice * Quantity"

When you create an expression for the filter, put the string in single quotes:

"LastName = 'Jones'"

The following characters are special characters, as explained below, if they are used for the column name must be escaped:

\n (newline)

\t (tab)

\r (carriage return)

~

(

)

#

\

/

=

>

<

+

-

*

%

&

|

^

'

"

[

]

If the column contains the name of one of the above character, the name must be enclosed in parentheses. For example, to use the column named "Column #" in an expression, should write "[Column #]":

Total * [Column#]

As the brackets is a special character, if it is an integral part of the name of the column, you must use the slash ( "\") in brackets will be escaped. For example, the name "Column []" column should be written:

Total * [Column[\]]

(Only the second bracket must be escaped.)

User-defined value

User-defined value may be used in the expression is compared with the column values. String value should be placed in single quotes. Date values ​​should be placed within a pound sign (#). For numeric, decimal and allows scientific notation. E.g:

"FirstName = 'John'"

"Price <= 50.00"

"Birthdate < #1/31/82#"

For enumeration value column contains the value of integer data type cast. E.g:

"EnumColumn = 5"

Operators

When used in series allows Boolean AND, OR and NOT operators. Parentheses may be used in combination clauses and forced priority. AND operator precedence over other operators. E.g:

(LastName = 'Smith' OR LastName = 'Jones') AND FirstName = 'John'

When you create a comparison expression, allowing the use of the following operators:

<

>

<=

>=

<>

=

IN

LIKE

In the expression further supports the following arithmetic operators:

+ (Plus)

-(Less)

* (Multiplication)

/(except)

% (Model number)

String operators

To connect strings, use the + character. Case-insensitive string comparisons are made DataSet class CaseSensitive determined attribute. However, use DataTable class CaseSensitive override this attribute value.

Tsuhaifu

In comparison LIKE,% *, and both can be used interchangeably as a wildcard. If the string contains LIKE clause * or%, then these characters applications brackets ([]) be escaped. If there are clauses in parentheses, then the bracket characters use brackets be escaped (for example, [[] or []]). Mode the beginning and end, or the end of the model, or at the beginning of the pattern allows the use of wildcards. E.g:

"ItemName LIKE '*product*'"

"ItemName LIKE '*product'"

"ItemName LIKE 'product*'"

Wildcards are not allowed in the middle of the string. For example, it is not allowed 'te * xt'.

Parent / child relationship references

In the front row by adding the name of the Parent , the parent table can be referenced in the expression. For example, Parent.Price reference name of the parent table Price column.

In front of the column name by adding a Child , the sub-table can be referenced in an expression columns. However, because child relationships can return multiple rows, you must include a reference sub-functions listed in the polymerization. For example, the Sum (Child.Price) returns the child table named Price sum of the column.

If a table multiple sub-table, the syntax is: Child (RelationName) . For example, if a table has two sub-tables, their names were Customers and the Orders , the DataRelation object is named Customers2Orders , reference will be:

Avg(Child(Customers2Orders).Quantity)

polymerization

Polymeric supports the following types:

Sum (sum)

Avg (average)

Min (minimum)

Max (maximum)

Count (Count)

StDev (statistical standard deviation)

Var (statistical variance).

The polymerization is usually performed along relationship. By using one of the above functions, "parent / child relationships referenced" listed above detailed sublist, to create the aggregate expressions. E.g:

Avg(Child.Price)

Avg(Child(Orders2Details).Price)

The polymerization can also be performed on a single table. For example, to create a summary for the column named "Price" in the figures, use:

Sum(Price)

Note that    if you use a table to create the aggregate, the combination does not function. Instead, all rows show the same value in the column.

If the table is not OK, the function returns a null reference polymerization (Visual Basic for Nothing ).

Data type can always be checked by columns DataType attribute is determined. Convert function may also be used to convert the data type, as shown below.

FUNCTIONS

Also supports the following functions:

CONVERT

description Given expression to a specified .NET Framework type.
grammar Convert(expression, type)
parameter expression The - expression to be converted.

type - value is converted into the .NET Framework type.

例如:myDataColumn.Expression="Convert(total, 'System.Int32')"

All conversions are valid only with the following exceptions: Boolean only with Byte , SByte , Int16 , Int32 , Int64 , UInt16 , UInt32 , UInt64 , String and its own conversion. Char only with Int32 , UInt32 , String and its own conversion. DateTime only with String and itself interchangeable. TimeSpan only with String and itself interchangeable.

ONLY

description Get the length of the string
grammar LEN(expression)
parameter expression The - string to evaluate.

例如:myDataColumn.Expression="Len(ItemName)"

ISNULL

description Check the expression and returns the checked expression or a replacement value return.
grammar ISNULL(expression, replacementvalue)
parameter expression The - To check the expression.

replacementvalue - If the expression is a null reference ( Nothing ), returns replacementvalue .

例如:myDataColumn.Expression="IsNull(price, -1)"

IIF

description The result of the logical expression, obtain one of two values.
grammar IIF(expr, truepart, falsepart)
parameter expr - the expression to be evaluated.

truepart - the expression is true value is returned.

falsepart - value expression is false is returned.

例如:myDataColumn.Expression = "IIF(total>1000, 'expensive', 'dear')

TRIM

description Removing all leading and suffix space characters, such as \ r, \ n, \ t, ''
grammar TRIM(expression)
parameter expression The - to trim expression.

SUBSTRING

description Obtaining from a specified point in the string, the substring having a specified length.
grammar SUBSTRING(expression, start,

length)

parameter expression The - source string substring.

start integer specifying the start position of substring -.

length - integer specifying the length of the substring.

例如:myDataColumn.Expression = "SUBSTRING(phone, 7, 8)"

Note that    can assure Expression assign a null or empty string attribute to reset the attribute. If the expression column is set to a default value, then reset the Expression after property, the default value is assigned to all previously been filled rows.

Reproduced in: https: //www.cnblogs.com/hdjjun/archive/2009/10/19/1586008.html

Guess you like

Origin blog.csdn.net/weixin_33963189/article/details/94497602