andrepires
asked on
Calculated Columns, Datatable and Dataset Questions
Hello!
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.
Questions:
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?
1) Whe
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.
Questions:
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?
1) Whe
To calculate it at run time, the best way is to use java script. on tab out of UnitPrice and Quantity text boxes or cells add a javascript function that multiplies these values and adds teh calcualted value in the totalPrice column
ASKER
Hi.
Iti is a windows forms application.
Iti is a windows forms application.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
ok.. this answer is for the question 1 and 2.
What about the question 3?
What about the question 3?
Does your datatable that is fetched from the database have this TotalPrice column?
ASKER
No sir...
It does no matter since I'm talking about a disconnected scenario using ADO.Net and XML.
The fact is that the WriteXML method of the dataset should save any element, such as tables, columns and data to the target XML file. It is including the TotalPrice element definition in the schema, but is not saving the calculation value...
It does no matter since I'm talking about a disconnected scenario using ADO.Net and XML.
The fact is that the WriteXML method of the dataset should save any element, such as tables, columns and data to the target XML file. It is including the TotalPrice element definition in the schema, but is not saving the calculation value...
When the cell is updated, iterate through the DataTable that you are using it to bind to the datagrid, update the datatable too.
ASKER
Ok.. it seams like it is a bug of VS 2003 and/or Datagrid.
I reproduced the same code using VS 2005 and everything is perfect.
I reproduced the same code using VS 2005 and everything is perfect.