Visual Basic Concepts
Displaying Calculated Fields
See Also
Suppose you have a field in a table named "Price," and you want to calculate the tax on every item in the table using the local tax rate. That is a calculated field, which you can create by modifying the query of the DataSource to calculate the value, and returning that value to the DataGrid control.
To create a calculated field in the DataGrid control
- Ensure that an OLE DB data source for the Northwind database is present on the machine; if such a data source has not been created, follow the steps in "Creating the Northwind OLE DB Data Link."
- Place an ADO Data control and a DataGrid control on the form.
- Set the ConnectionString property of the ADO Data control to the Northwind Data Source.
- Set the RecordSource property of the ADO Data control.
On the Properties window, click RecordSource and type Select ProductName, UnitPrice, (UnitPrice * .082) As Tax From Products.
- Set the DataSource property of the DataGrid control to the ADO Data control.
- Run the project.