davoman
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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").Colu mns.Add(dc )
http://home.hot.rr.com/graye/Articles/ADO_Expressions.htm
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").Colu
http://home.hot.rr.com/graye/Articles/ADO_Expressions.htm
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
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
ASKER
Thanks that was just what i needed :)
ASKER