Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Sum the fields in Windows Forms DataGrid

Sum the fields in Windows Forms DataGrid

Scheduled Pinned Locked Moved Database
csharpdatabasequestionwinformstools
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zvfil001
    wrote on last edited by
    #1

    Hi was wondering if anybody could help me. I was maid stored procedure as following: USE [Spacva] GO /****** Object: StoredProcedure [dbo].[Test] Script Date: 11/13/2007 11:12:51 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[Test] ( @START_DATE smalldatetime, @END_DATE smalldatetime ) AS BEGIN SELECT VOZILA.ID_VOZILA, VOZILA.PROIZVODNI_POGON, VOZILA.NAZIV, VOZILA.TIP, VOZILA.REG, SUM(TOCENJE.KOL_L) AS Quantity, SUM(TOCENJE.SATI_RADA) AS Hours, SUM(TOCENJE.PROSJEK_L_PO_H) AS Average FROM VOZILA INNER JOIN TOCENJE ON VOZILA.ID_VOZILA = TOCENJE.ID_VOZILA WHERE (TOCENJE.DATUM_UNOSA BETWEEN CONVERT(SMALLDATETIME, @START_DATE, 104) AND CONVERT(SMALLDATETIME, @END_DATE, 104)) GROUP BY VOZILA.ID_VOZILA, VOZILA.PROIZVODNI_POGON, VOZILA.NAZIV, VOZILA.TIP, VOZILA.REG END That stored procedure I was include in my Windows C# Project, just drag and drop to Win Form. My question is, how to add footer in established DataGrid, I mean how to add SUM of all selected values from column Quantity to my DataGrid? I'm new in SQL, Visual .NET, C# so thanks in advance for help! Zvonimir

    D 1 Reply Last reply
    0
    • Z zvfil001

      Hi was wondering if anybody could help me. I was maid stored procedure as following: USE [Spacva] GO /****** Object: StoredProcedure [dbo].[Test] Script Date: 11/13/2007 11:12:51 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[Test] ( @START_DATE smalldatetime, @END_DATE smalldatetime ) AS BEGIN SELECT VOZILA.ID_VOZILA, VOZILA.PROIZVODNI_POGON, VOZILA.NAZIV, VOZILA.TIP, VOZILA.REG, SUM(TOCENJE.KOL_L) AS Quantity, SUM(TOCENJE.SATI_RADA) AS Hours, SUM(TOCENJE.PROSJEK_L_PO_H) AS Average FROM VOZILA INNER JOIN TOCENJE ON VOZILA.ID_VOZILA = TOCENJE.ID_VOZILA WHERE (TOCENJE.DATUM_UNOSA BETWEEN CONVERT(SMALLDATETIME, @START_DATE, 104) AND CONVERT(SMALLDATETIME, @END_DATE, 104)) GROUP BY VOZILA.ID_VOZILA, VOZILA.PROIZVODNI_POGON, VOZILA.NAZIV, VOZILA.TIP, VOZILA.REG END That stored procedure I was include in my Windows C# Project, just drag and drop to Win Form. My question is, how to add footer in established DataGrid, I mean how to add SUM of all selected values from column Quantity to my DataGrid? I'm new in SQL, Visual .NET, C# so thanks in advance for help! Zvonimir

      D Offline
      D Offline
      dhbaer
      wrote on last edited by
      #2

      You either have two options. Either manually iterate through the items in the datagrid after it is populated, do the sum and add a row. Or you can do some 'ROLLUP' functionality in the SQL query so when you pull it down into the datagrid, it already has the sum values you want in their own row(s).

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups