Click here to Skip to main content
13,089,536 members (64,925 online)
Rate this:
Please Sign up or sign in to vote.
i am doing a c# project i working with visual studio and i have a winform in that there is two combobox the first is of month and second is of year and a button by the side. and i have a table. in that table there is two column named "date" which is having datatype smalldatetime. and another is "price" which is varchar when the button is clicked i want that according to the month and year it checkes the table and display the total sum of the column of price in a label. is that possible to do? i am not using any datagrid or anything dataview such type. i am using a label to display can i calculate and show the sum?
Posted 15-Jan-13 2:46am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Following query may help

select sum(price)
from yourtable

Don't have SQL access at present, so check syntax, though logically thsi si correct

Hope that helps
hemantrautela 15-Jan-13 9:12am
datepart(), it returns numeric value

For Detail
Milind_T 15-Jan-13 9:15am
Yes Hemantrautela, it will return integer. OP hasn't made clear what heshe has got in the combobox though. But you can always convert in to number.
shaikh-adil 15-Jan-13 9:44am
sir i am using entity framework. Then it will help? This query can be used to display sum in a label.text?
hemantrautela 15-Jan-13 10:29am
Why not try it yourself...

It is valid sql query & you get the sum of price. then you can use this value anywhere...
shaikh-adil 15-Jan-13 12:45pm
sir your answer is correct (thank you really for helping me and newbies) can you further help me that can i count the total number of rows in that column? what i have to made changes?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 15 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100