Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL Access WinForm
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.. Smile | :)
Posted 24-Feb-13 4:53am
Comments
braop at 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
good
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.
  Permalink  
Rate this: bad
good
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!
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 205
3 Jochen Arndt 180
4 Sergey Alexandrovich Kryukov 165
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,650
3 Kornfeld Eliyahu Peter 3,460
4 Sergey Alexandrovich Kryukov 2,811


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 24 Feb 2013
Copyright © CodeProject, 1999-2014
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