DataColumn.Expression 속성

정의

행을 필터링하거나 열의 값을 계산하거나 집계 열을 만드는 데 사용되는 식을 가져오거나 설정합니다.

public:
 property System::String ^ Expression { System::String ^ get(); void set(System::String ^ value); };
[System.Data.DataSysDescription("DataColumnExpressionDescr")]
public string Expression { get; set; }
public string Expression { get; set; }
[<System.Data.DataSysDescription("DataColumnExpressionDescr")>]
member this.Expression : string with get, set
member this.Expression : string with get, set
Public Property Expression As String

속성 값

열 값을 계산하거나 집계 열을 만드는 식입니다. 식의 반환 형식은 열에 DataType 의해 결정됩니다.

특성

예외

AutoIncrement 또는 Unique 속성이 .로 설정됩니다true.

CONVERT 함수를 사용하는 경우 식은 문자열로 계산되지만 문자열에는 형식 매개 변수로 변환할 수 있는 표현이 포함되어 있지 않습니다.

CONVERT 함수를 사용하는 경우 요청된 캐스트를 사용할 수 없습니다. 가능한 캐스트에 대한 자세한 내용은 다음 섹션의 변환 함수를 참조하세요.

SUBSTRING 함수를 사용하는 경우 시작 인수가 범위를 벗어났습니다.

-또는-

SUBSTRING 함수를 사용하는 경우 길이 인수가 범위를 벗어났습니다.

LEN 함수 또는 TRIM 함수를 사용하는 경우 식은 문자열로 계산되지 않습니다. 여기에는 으로 계산 Char되는 식이 포함됩니다.

예제

다음 예제에서는 에 세 개의 DataTable열을 만듭니다. 두 번째 및 세 번째 열에는 식이 포함됩니다. 두 번째는 가변 세율을 사용하여 세금을 계산하고, 세 번째는 계산 결과를 첫 번째 열의 값에 추가합니다. 결과 테이블이 컨트롤에 DataGrid 표시됩니다.

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;
}
Private Sub CalcColumns()
     Dim rate As Single = .0862
     Dim table As New DataTable()
 
     ' Create the first column.
     Dim priceColumn As New DataColumn()
     With priceColumn
         .DataType = System.Type.GetType("System.Decimal")
         .ColumnName = "price"
         .DefaultValue = 50
     End With
     
     ' Create the second, calculated, column.
     Dim taxColumn As New DataColumn()
     With taxColumn
         .DataType = System.Type.GetType("System.Decimal")
         .ColumnName = "tax"
         .Expression = "price * 0.0862"
     End With
     
    ' Create third column
     Dim totalColumn As 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 Sub

설명

이 API에 대한 자세한 내용은 DataColumn.Expression에 대한 추가 API 비고를 참조하세요.

적용 대상

추가 정보