How to: Create an Expression Column (Visual Basic)
This example creates a DataColumn object and sets the DataColumn.Expression property to calculate the order total (without the discount!).
Example
Private Sub CreateExpressionColumn()
Dim orderTotal As New DataColumn()
orderTotal.ColumnName = "OrderTotal"
orderTotal.DataType = GetType(Double)
orderTotal.Expression = "UnitPrice * Quantity"
dsNorthwind1.Order_Details.Columns.Add(orderTotal)
End Sub
Compiling the Code
This example requires:
A project reference to System.data.dll.
Access to the members of the System.Data namespace. Add an Imports statement if you are not fully qualifying member names in your code. For more information, see Imports Statement.
An instance of a typed dataset named
dsNorthwind1
.The
OrderDetails
table in thedsNorthwind1
dataset.
Robust Programming
The following conditions may cause an exception:
- The database is unavailable (OleDbException Class, SqlException Class, OdbcException Class, or OracleException Class, exception will be specific to your database).
See Also
Reference
Concepts
Creating Expression Columns
Adding Columns to a Table
Other Resources
Accessing Data (Visual Studio)
ADO.NET
Preparing Your Application to Receive Data
Editing Data in Your Application