6 Replies - 656 Views - Last Post: 06 October 2012 - 06:24 AM Rate Topic: -----

#1 Thantanenorn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-October 12

Getting the sum of the column

Posted 06 October 2012 - 02:26 AM

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
Is This A Good Question/Topic? 0
  • +

Replies To: Getting the sum of the column

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

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.
Was This Post Helpful? 0
  • +
  • -

#3 Thantanenorn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-October 12

Re: Getting the sum of the column

Posted 06 October 2012 - 05:51 AM

I have a table tblOrders with ShippedDate

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
Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

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.
Was This Post Helpful? 0
  • +
  • -

#5 Thantanenorn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-October 12

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
Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

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

This post has been edited by CharlieMay: 06 October 2012 - 06:18 AM

Was This Post Helpful? 0
  • +
  • -

#7 Thantanenorn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-October 12

Re: Getting the sum of the column

Posted 06 October 2012 - 06:24 AM

Got it, Thanks for the help Mr.Charlie ~ SOLVE :bananaman: :bananaman:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1