Click here to Skip to main content
15,662,459 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.. :)
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

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.
Share this answer
" [Month of Purchase] "
this is wrong

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

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