DataColumn.Expression 속성

정의

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

public:
 property System::String ^ Expression { System::String ^ get(); void set(System::String ^ value); };
public string Expression { get; set; }
[System.Data.DataSysDescription("DataColumnExpressionDescr")]
public string Expression { get; set; }
member this.Expression : string with get, set
[<System.Data.DataSysDescription("DataColumnExpressionDescr")>]
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 설명을 참조하세요.

적용 대상

추가 정보