Click here to Skip to main content
15,915,065 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.
Posted
Updated 19-Feb-13 8:15am
v3
Comments
Maciej Los 19-Feb-13 14:19pm    
and the data comes from???
Navas Khanj 19-Feb-13 14:22pm    
Table

If you can get the data from table, use this:
SQL
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
 
Comments
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.
—SA
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.
—SA
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 (http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)[^]):

MVVM — Model View View Model,
http://en.wikipedia.org/wiki/Model_View_ViewModel[^],

MVC — Model-View-Controller,
http://en.wikipedia.org/wiki/Model-view-controller[^]),

MVA — Model-View-Adapter,
http://en.wikipedia.org/wiki/Model–view–adapter[^],

MVP — Model-View-Presenter,
http://en.wikipedia.org/wiki/Model-view-presenter[^].
Pay attention for the motivation of those architectures. If you understand it, you would be able to create better design ideas.

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

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