Click here to Skip to main content
13,093,184 members (81,912 online)
Rate this:
Please Sign up or sign in to vote.
See more:
hi!! i need to return the sum of price from purchases table, but i am not getting the value...

the value is displayed on label..

this is the code...

string stat = "SELECT SUM(Price)as Price from Purchases WHERE [Month of Purchase] = '" + purch_month + "'";

OleDbCommand cmd = new OleDbCommand(stat, con);

can someone help me with this problem..

Thanks in Advance.. :)
Posted 24-Feb-13 3:53am
braop 24-Feb-13 10:13am
i think problem is with your sql query:
1). if u to display ur values in a label why do u use "as Price"
2). what is [Month of Purchase] is it a field in table purchase or what? use MonthofPurchase
3). the two coats ('') on your purch_month indicate its a string, yet month is supposed to be date

can u try using parametrized queries or look for way to convert purch_month to date
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You do not mention where the problem or find any exception or not. First of all make sure that your sql query is fine. You just retrive stat value from your application by debugging. That stat variable value you copy and directly past it to sqlserver Management studio and see it returns any value or not. If it return value then if you can use cmd.ExecuteScalar method then it will return the sum value.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

" [Month of Purchase] "
this is wrong

i dont remember but i guess you shoud use some thing like:
month(Purchase.Date) = something!

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 |
Web04 | 2.8.170813.1 | Last Updated 24 Feb 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