Export (0) Print
Expand All

How to: Create Data Columns that Display Expressions 

A data table in a dataset can contain columns in which the value is calculated rather than read from the database. For example, in an order details record, it might make sense to define an ExtendedPrice column by multiplying the quantity times the price, rather than actually storing the total in the record. Calculated columns can also add or count values in child records and filter other records. You can define calculated columns using expressions.

The syntax of the expression consists of standard operators. You can reference a data value using its column name (as you would in an SQL statement) and include aggregate functions such as Count.

For example, the expression for an ExtendedPrice column based on the UnitPrice times Quantity columns of the current record might simply be:

UnitPrice * Quantity

To refer to columns in child tables, you can use the reserved word Child, followed by the name of the column. For example, the following expression returns the average value of the Price column in all related child records:

Avg(Child.Price)

For more information, see the Expression property.

You can create expression columns in the Dataset Designer. For more information about creating columns, see How to: Add Columns to a DataTable.

NoteNote

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To create column expressions in the Dataset Designer

  1. Open your dataset in the Dataset Designer. For more information, see How to: Open a Dataset in the Dataset Designer.

  2. In the data table that you want, select the column you want to add the expression to, or add a new column to the table. For more information, see How to: Add Columns to a DataTable.

  3. In the Properties window, enter an expression in the Expression property.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft