.net中除正则以外的 用于筛选行、计算列中的值或创建聚合列 可用于表中
JScript
Public Property Expression As String Get Set
Public Property Expression As StringGetSet
public string Expression { get; set; }public string Expression { get; set; }public:property String^ Expression { String^ get (); void set (String^ value);}public:property String^ Expression {String^ get ();void set (String^ value);}member Expression : string with get, set
member Expression : string with get, set
..::. String
用来计算列的值,或创建聚合列的表达式。表达式的返回类型由列的 DataType 来确定。
DataSet1.Tables("Orders").Columns("OrderCount").Expression = "Count(OrderID)"说明
如果在表达式中使用了某个列,则该表达式就存在一个对该列的依赖项。重命名或移除依赖列时不会引发异常。当访问缺少了依赖项的表达式列时,将引发异常。
在为筛选器创建表达式时,用单引号将字符串括起来:
"LastName = 'Jones'"
如果列名称包含任何非字母数字字符、以数字开头或匹配(不分大小写)以下任意的保留字,则它需要特殊处理,如下面的段落中所述。
与
之间
子级
False
隶属
Is
Like
Not
Null
Or
父级
True
如果列名称满足上述条件之一,则它必须被包括在方括号中或在“`”(重音符)引号中。例如,若要在表达式中使用名为“Column#”的列,应写成“[Column#]”:
Total * [Column#]
或 "`列号`":
Total * `Column#`
如果列名称括在方括号中,则必须通过在所有“]”和“\”字符(不是任何其他字符)前添加反斜杠(“\”)字符来跳过这些字符。如果列名称括在重音字符中,则它不能包含任何重音字符。例如,名为“Column[]\”的列应写成:
Total * [Column[\]\\]
或
Total * `Column[]\`
说明
如果使用一个表来创建聚合,将没有组合功能。相反,所有行都在列中显示相同的值。
如果表没有行,聚合函数将返回 nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing) 。
数据类型总是可以通过检查列的 DataType 属性来确定。 还可以使用 Convert 函数来转换数据类型,如下面这一部分所示。
nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing) ,则返回 说明
可以向 C++F#JScript
Private Sub CalcColumns() Dim rate As Single = .0862 dim table as DataTable = New DataTable ' Create the first column. Dim priceColumn As DataColumn = New DataColumn With priceColumn .DataType = System.Type.GetType("System.Decimal") .ColumnName = "price" .DefaultValue = 50 End With ' Create the second, calculated, column. Dim taxColumn As DataColumn = New DataColumn With taxColumn .DataType = System.Type.GetType("System.Decimal") .ColumnName = "tax" .Expression = "price * 0.0862" End With ' Create third column Dim totalColumn As DataColumn = New DataColumn With totalColumn .DataType = System.Type.GetType("System.Decimal") .ColumnName = "total" .Expression = "price + tax" End With ' Add columns to DataTable With table.Columns .Add(priceColumn) .Add(taxColumn) .Add(totalColumn) End With Dim row As DataRow= table.NewRow table.Rows.Add(row) Dim view As New DataView view.Table = table DataGrid1.DataSource = view End SubPrivate Sub CalcColumns() Dim rate As Single = .0862 dim table as DataTable = New DataTable ' Create the first column. Dim priceColumn As DataColumn = New DataColumn With priceColumn .DataType = System.Type.GetType("System.Decimal") .ColumnName = "price" .DefaultValue = 50 End With ' Create the second, calculated, column. Dim taxColumn As DataColumn = New DataColumn With taxColumn .DataType = System.Type.GetType("System.Decimal") .ColumnName = "tax" .Expression = "price * 0.0862" End With ' Create third column Dim totalColumn As DataColumn = New DataColumn With totalColumn .DataType = System.Type.GetType("System.Decimal") .ColumnName = "total" .Expression = "price + tax" End With ' Add columns to DataTable With table.Columns .Add(priceColumn) .Add(taxColumn) .Add(totalColumn) End With Dim row As DataRow= table.NewRow table.Rows.Add(row) Dim view As New DataView view.Table = table DataGrid1.DataSource = view End Subprivate void CalcColumns(){ DataTable table = new DataTable (); // Create the first column. DataColumn priceColumn = new DataColumn(); priceColumn.DataType = System.Type.GetType("System.Decimal"); priceColumn.ColumnName = "price"; priceColumn.DefaultValue = 50; // Create the second, calculated, column. DataColumn taxColumn = new DataColumn(); taxColumn.DataType = System.Type.GetType("System.Decimal"); taxColumn.ColumnName = "tax"; taxColumn.Expression = "price * 0.0862"; // Create third column. DataColumn totalColumn = new DataColumn(); totalColumn.DataType = System.Type.GetType("System.Decimal"); totalColumn.ColumnName = "total"; totalColumn.Expression = "price + tax"; // Add columns to DataTable. table.Columns.Add(priceColumn); table.Columns.Add(taxColumn); table.Columns.Add(totalColumn); DataRow row = table.NewRow(); table.Rows.Add(row); DataView view = new DataView(table); dataGrid1.DataSource = view;}private void CalcColumns(){ DataTable table = new DataTable (); // Create the first column. DataColumn priceColumn = new DataColumn(); priceColumn.DataType = System.Type.GetType("System.Decimal"); priceColumn.ColumnName = "price"; priceColumn.DefaultValue = 50; // Create the second, calculated, column. DataColumn taxColumn = new DataColumn(); taxColumn.DataType = System.Type.GetType("System.Decimal"); taxColumn.ColumnName = "tax"; taxColumn.Expression = "price * 0.0862"; // Create third column. DataColumn totalColumn = new DataColumn(); totalColumn.DataType = System.Type.GetType("System.Decimal"); totalColumn.ColumnName = "total"; totalColumn.Expression = "price + tax"; // Add columns to DataTable. table.Columns.Add(priceColumn); table.Columns.Add(taxColumn); table.Columns.Add(totalColumn); DataRow row = table.NewRow(); table.Rows.Add(row); DataView view = new DataView(table); dataGrid1.DataSource = view;}平台