Calculated Columns, Datatable and Dataset Questions
Posted on 2007-10-04
In Visual Studio 2003, I used the properties window of an untyped dataset object to create the dataset's tables, columns, etc...
Let's say that I created a table called Orders and that table has 3 columns: OrderID, UnitPrice and Quantity.
Now I want to add a calculated column to the table. The calculated column will be named TotalPrice and its Expression Property will be set to the value "UnitPrice * Quantity".
Now I add code to fill my custom dataset with data from the database and use it as a datasource for my datagrid.
1) When I add a new row to the grid and insert values to the columns UnitPrice and Quanity (let's say $10 and 23), my TotalPrice column is not being calculated. I suppose that the calculation is done when the data is being retrieved from the database... Am I right?
2) How to make it calculate the TotalPrice when I type the values on the UnitPrice and Quantity columns at run-time?
3) Now suppose that I use the WriteXML method of the datase to save the dataset schema and data to an XML file... It is not saving the calculated column. Why?