Adding controls to a DataWindow object
206 DataWindow .NET
• In the DataWindow painter, you can define computed fields after you have
defined the
SELECT statement (or other data source).
The difference
between the two ways
When you define the computed column in the Select painter, the value is
calculated by the DBMS when the data is retrieved. The computed column's
value does not change until data has been updated and retrieved again.
When you define the computed field in the DataWindow painter, the value of
the column is calculated in the DataWindow object after the data has been
retrieved. The value changes dynamically as the data in the DataWindow
object changes.
Example
Consider a DataWindow object with four columns: Part number, Quantity,
Price, and Cost. Cost is computed as Quantity * Price.
If
Cost is defined as a computed column in the Select painter, the SELECT
statement is as follows:
SELECT part.part_num,
part.part_qty,
part.part_price,
part.part_qty * part.part_price
FROM part;
If the user changes the price of a part in the DataWindow object in this
scenario, the cost does not change in the DataWindow object until the database
is updated and the data is retrieved again. The user sees a display with the
changed price but the unchanged, incorrect cost.
If
Cost is defined as a computed field in the DataWindow object, the SELECT
statement is as follows, with no computed column:
SELECT part.part_num,
part.part_qty,
part.part_price
FROM part;
The computed field is defined in the DataWindow object as Quantity *
Price
.
Part # Quantity Price Cost
101 100 1.25 125.00
Part # Quantity Price Cost
101 100 2.50 125.00