Visual Basic Concepts

Displaying Calculated Fields

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

  1. 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."

  2. Place an ADO Data control and a DataGrid control on the form.

  3. Set the ConnectionString property of the ADO Data control to the Northwind Data Source.

  4. 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.

  5. Set the DataSource property of the DataGrid control to the ADO Data control.

  6. Run the project.