Click here to Skip to main content
15,789,776 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to Sum total amount in DataGridView
Column1	Column2	Column3	Column n	 TOTAL
500	100	300	900
200	75	100	375
100	25	150	275
400	50	225	675
500	100	450	1050

Please tell me how to sum total.
Updated 19-Feb-13 9:15am
Maciej Los 19-Feb-13 14:19pm    
and the data comes from???
Navas Khanj 19-Feb-13 14:22pm    

If you can get the data from table, use this:
SELECT Column1, Column2, Column3, ColumnN, (Column1 + Column2 + Column3 + ColumnN) AS TOTAL
FROM TableName

Do not forget to use COALESCE()[^] function. Why? Read it.
Share this answer
Sergey Alexandrovich Kryukov 19-Feb-13 18:40pm    
It might not be the correct question, just because OP only answered "table", without any detail, so who knows what is that?
Nevertheless, I voted 5, because all of the above is not so important. What is important, is the idea to have some data layers and work with this data layer, without using a broken telephone of the UI.
Messing with UI messes up isolation between layers and makes project non-maintainable.
Maciej Los 20-Feb-13 12:33pm    
Thank you, Sergey ;)
Sergey Alexandrovich Kryukov 19-Feb-13 18:42pm    
In view of that, I decide to elaborate. Please see Solution 2.
Please see the Solution 1, taking into account my comment to it. You were moving in wrong direction.

I suggest you learn and analyze applicability of the following architectural patterns ([^]):

MVVM — Model View View Model,[^],

MVC — Model-View-Controller,[^]),

MVA — Model-View-Adapter,–view–adapter[^],

MVP — Model-View-Presenter,[^].
Pay attention for the motivation of those architectures. If you understand it, you would be able to create better design ideas.

Share this answer
Maciej Los 20-Feb-13 12:33pm    
Good suggestion, my 5!
Sergey Alexandrovich Kryukov 20-Feb-13 14:10pm    
Thank you, Maciej.

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