OrderId CustomerID BookID ShipVia ShipAddress Quantity TotalPrice
1 1 12 9 BlahBlah 100 1500
2 1 11 10 BlohBloh 100 700
This is my DataGridView and SQL result, how can I add all the totalprice and put it on a textbox ? anyone ? thanks
Getting the sum of the column
Page 1 of 16 Replies - 261 Views - Last Post: 06 October 2012 - 06:24 AM
Replies To: Getting the sum of the column
#2
Re: Getting the sum of the column
Posted 06 October 2012 - 04:56 AM
You can either sum it with a SELECT statement based off the same criteria as you used to populate the dgv or you can use a For Each or For Next loop to gather each cell's value and add it to a variable. Then it's just a matter of either displaying the result of the Query or the Variable's result to the textbox.
#3
Re: Getting the sum of the column
Posted 06 October 2012 - 05:51 AM
I have a table tblOrders with ShippedDate
Here's my SQL and it doesn't show any result in my datagridview , when I remove the where condition it shows the sum of the totalPrice but what I want is to show according into the input ShippedDate
No errors, just in the datagridView you can see the TotalPrice but there's no value
sql = "select sum(totalPrice)as TotalPrice from tblOrders where ShippedDate between '" & oQuarterlySalesBO.startingDate & "' and '" & oQuarterlySalesBO.endDate & "'"
Here's my SQL and it doesn't show any result in my datagridview , when I remove the where condition it shows the sum of the totalPrice but what I want is to show according into the input ShippedDate
No errors, just in the datagridView you can see the TotalPrice but there's no value
#4
Re: Getting the sum of the column
Posted 06 October 2012 - 06:09 AM
Then there is something wrong with the values in the where clause. Meaning, it didn't find something in the date range. Try putting the two dates in and see if it comes up with a result. Debug and look at what oQuarterlySalesBO.Start and EndDate contains.
#5
Re: Getting the sum of the column
Posted 06 October 2012 - 06:15 AM
sql = "select sum(totalPrice)as TotalPrice from tblOrders where ShippedDate between ' Saturday,October 6,2012' and 'Sunday,October 7, 2012'"
when I try this one, it shows the correct query , what is the problem when it comes to oQuarterlySalesBO ? grrrr
#6
Re: Getting the sum of the column
Posted 06 October 2012 - 06:17 AM
First, put your objects back in and set a breakpoint after that line. Run your program to this point and it will break execution when it reaches the breakpoint. Move your mouse over the objects start and end date properties to see what values they hold. It could be that the values they hold are not what you're expecting for some reason beyond this block of code.
Edited for clarification
Edited for clarification
This post has been edited by CharlieMay: 06 October 2012 - 06:18 AM
#7
Re: Getting the sum of the column
Posted 06 October 2012 - 06:24 AM
Got it, Thanks for the help Mr.Charlie ~ SOLVE
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|