|
-
May 20th, 2007, 09:39 PM
#1
Thread Starter
Addicted Member
[2005] Computing Total value Based on Content in two Columns
Hi,
I have two columns in two different DataGridViews that I would like to Sum up to arrive at the value that is to show up in my WORKORDERTOTAL textbox, what I have now does not work at all. How do I best calculate this sort of expression ?
2) Others have to display other values but What I notice is that I need to actually click on the textboxes for the computation to show up. Is there a better way to handle this please?
Code:
txtQtyTotal.Text = (DS.Tables("LineItems").Compute("Sum(QUANTITYRECORDED)", "QUANTITYRECORDED <= 10000000")).ToString
txtTotals.Text = (DS.Tables("LineItems").Compute("Sum(TOTALCOST)", "TOTALCOST <= 10000000")).ToString
txtWORKORDERTOTAL.Text = (DS.Tables("LineItems").Compute("Sum(TOTALCOST)", "TOTALCOST <= 10000000")).ToString
txtWORKORDERTOTAL.Text += (DS.Tables("PackedLineItems").Compute("Sum(TOTALCOST)", "TOTALCOST <= 10000000")).ToString
thanks in Advance
Reaction
-
May 20th, 2007, 09:56 PM
#2
Re: [2005] Computing Total value Based on Content in two Columns
Look at this code:
vb.net Code:
txtWORKORDERTOTAL.Text += (DS.Tables("PackedLineItems").Compute("Sum(TOTALCOST)", "TOTALCOST <= 10000000")).ToString
Both sides of the '+=' operator are String objects. What happens when you "add" two strings? They are concatenated into one longer string. If you want to perform mathematical addition on two numbers then you have to use numbers, not strings. The Compute method will return an Object reference that will contain a value of the same type as the column you're aggregating. If the TotalCost column is type Integer then Compute will return an Integer. Likewise for Double, Decimal etc. You should be casting the result of the Compute method as the appropriate type using Cint, CDbl or whatever. THEN you will have number sthat you can add together.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|