C# DataColumn.Expression

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

예제

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;

}