Let’s add a Total field to the Orders controller. This field will add Subtotal and Freight together to show the final cost of the whole order.
In the Project Explorer, select the Orders controller, and right-click on Fields. Press New Field.
Give this new field the following settings:
|The value of this field is computed at run-time by SQL Expression||
(select sum(unitprice*quantity*(1-discount)) from "order details" where "Order Details".OrderID = Orders.OrderID) + Orders.Freight
|The value of this field is calculated by a business rule expression||
CalculateOrderDetailsTotal(orderID) + freight
|Data Format String||c|
|Values of this field cannot be edited||True|
|Context Fields||OrderDetails, Freight|
Press OK to save this field.
We’ll need to bind this field to the data views. In the Project Designer, switch to Data Fields tab. On the action bar, press New | New Data Field. Use the following settings:
Press OK to save the data field. Double-click on Total field again, and create another data field with the following settings:
Save the data field, and regenerate the application. Navigate to the Order Form page, and select any order. You will see a Total field that sums up Subtotal and Freight.