Sum

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • OuTCasT
    Contributor
    • Jan 2008
    • 374

    Sum

    i am printing a datagridview into excel sheet.....
    now the columns all work out, one column is like Profit column and the other is a Profit % column

    Now i cant add a row to the datagridview programmaticall y because it is databound, i need to sum the profit column in the same sql statement as when im working out everything....

    here is how ive done the datagridview... .

    [CODE=sql]select Date,ProductID, Description,Buy ingPrice,Sellin gPrice,Profit_R =(sellingprice-buyingprice),Pr ofit=(sellingpr ice-buyingprice)/(sellingprice/100),Sold=(quan tity),Turnover= (quantity*selli ngprice),Profit Total=(sellingp rice-buyingprice)*(q uantity) from orders where date = '" & lbldate.Text & "'", sqlCon[/CODE]

    all i need now is to sum up the TURNOVER column and add it to the same datagridview so that it can be printed along with the datagridview print.....
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Originally posted by OuTCasT
    i am printing a datagridview into excel sheet.....
    now the columns all work out, one column is like Profit column and the other is a Profit % column

    Now i cant add a row to the datagridview programmaticall y because it is databound, i need to sum the profit column in the same sql statement as when im working out everything....

    here is how ive done the datagridview... .

    [CODE=sql]select Date,ProductID, Description,Buy ingPrice,Sellin gPrice,Profit_R =(sellingprice-buyingprice),Pr ofit=(sellingpr ice-buyingprice)/(sellingprice/100),Sold=(quan tity),Turnover= (quantity*selli ngprice),Profit Total=(sellingp rice-buyingprice)*(q uantity) from orders where date = '" & lbldate.Text & "'", sqlCon[/CODE]

    all i need now is to sum up the TURNOVER column and add it to the same datagridview so that it can be printed along with the datagridview print.....
    option 1:
    handle it on your GUI. during population, you can add each time the row is incremented or if your GUI to add a variable object and simple click "sum" and it's doing the rest...or

    option 2:
    run another query
    select Turnover=(quant ity*sellingpric e),ProfitTotal= (sellingprice-buyingprice)*(q uantity) from orders where date = '" & lbldate.Text & "'", sqlCo

    -- ck

    Comment

    • OuTCasT
      Contributor
      • Jan 2008
      • 374

      #3
      Originally posted by ck9663
      option 1:
      handle it on your GUI. during population, you can add each time the row is incremented or if your GUI to add a variable object and simple click "sum" and it's doing the rest...or

      option 2:
      run another query
      select Turnover=(quant ity*sellingpric e),ProfitTotal= (sellingprice-buyingprice)*(q uantity) from orders where date = '" & lbldate.Text & "'", sqlCo

      -- ck
      ive used another select statement which loads when the datagridview loads with its data
      [CODE=sql]
      (select SUM(profit) from orders where date = ' " & lblDate.text " ' ",sqlcon)[/CODE]

      but i need to get that into the datagrid
      i tried to insert a row manually like this
      [CODE=vb]withme.datagrid view1.rows.add( "Total Profit")[/CODE]
      but it says cannot add rows programmaticall y to datagridview when datagridview is data bound

      Comment

      Working...