Link to home
Start Free TrialLog in
Avatar of davoman
davomanFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Calculated in datasets

Hi there

Probably an easy one but can I calculate in datasets, basically i need to caluclate the result of too coulmns and enteret them into another column on the dataset before updatting the changes back to the server

is this possible and has anyone any sample code to point me in the right direction

regards

steve
ASKER CERTIFIED SOLUTION
Avatar of Sancler
Sancler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of davoman

ASKER

ok this looks good i will try it out
ADO.Net support the concept of Expressions...   You can create an 3rd column in your DataTable and assign it an expression that will automagically perform the math on the other two columns.   The cool part is that it happens in real time, so if you change on of the dependent columns, the expression column will update also.

Here is a trivial example:

      Dim dc As DataColumn
      dc = New DataColumn("TotalStock")
      dc.DataType = GetType(Integer)
      dc.Expression = "UnitsInStock + UnitsOnOrder" ' two column types
      ds.Tables("Products").Columns.Add(dc)

http://home.hot.rr.com/graye/Articles/ADO_Expressions.htm
Avatar of Sancler
Sancler

graye

I agree.  The only problem with that approach here might be the bit in the question that says "before updatting the changes back to the server".  It sounds like it's an existing column that is being recalculated and adding an expression column might make writing back more difficult.

Still, it is a choice and if davoman wants to go down that route, any such difficulties can be overcome.

Roger
Avatar of davoman

ASKER

Thanks that was just what i needed :)