Click here to Skip to main content
14,696,432 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
How to sum of two rows values inside the DataGridView, if the id of the both rows same and create one rows instead of two rows in the DataGrid?



Like the following example:

id          quantity       Bonus        price           total
 
01             25           10           123            4305
 
01             5             10          123            1845
 

I want to sum of the above two rows like this in the DataGrid.


id           quantity        Bonus         price          total
 
01              30            20             246          6150


if i take loop on it then duplicate value insert in the datagridview.
Posted
Comments
Atyant Srivastava 17-Jul-14 6:13am
   
you can do this logic before binding your DataGridView, then bind the result set with DataGridView
ZurdoDev 17-Jul-14 7:10am
   
I would recommend you do that in Sql.
Maciej Los 17-Jul-14 7:49am
   
Not enough information...

If your data comes from SQL database, use query like this:
SELECT id, SUM(quantity) AS quantity, SUM(Bonus) AS Bonus, SUM(price) AS price, SUM(total) AS total
FROM YourTableName
GROUP BY id
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900