We help IT Professionals succeed at work.

Calculated Columns, Datatable and Dataset Questions

andrepires
andrepires asked
on
723 Views
Last Modified: 2013-11-07
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
Comment
Watch Question

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

Author

Commented:
Hi.
Iti is a windows forms application.
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
ok.. this answer is for the question 1 and 2.
What about the question 3?
Does your datatable that is fetched from the database have this TotalPrice column?

Author

Commented:
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...
When the cell is updated, iterate through the DataTable that you are using it to bind to the datagrid, update the datatable too.

Author

Commented:
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.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.