Data retrieving from SQL Server with C#

Mar 14 2010 4:21 AM

I am trying to retrieve the data between two dates using C# with SQL Server database. I am passing dates entered in two text boxes to the sql statement as show below
"SELECT SUM(CONVERT(DECIMAL(6,2),howmuchspent)) AS totalexpenses FROM MONTHLYEXPENSES WHERE expensesdate BETWEEN ' " + fromdate.Text + " ' AND '" + todate.Text + "' ";
With the statement above I am getting data that from the required date range and also data that is out of date range too.
When I tested the statement in SQL Server query screen by giving dates as follows
SELECT SUM(CONVERT(DECIMAL(6,2),howmuchspent)) AS totalexpenses FROM MONTHLYEXPENSES WHERE expensesdate BETWEEN ' 03/01/2010
' AND '03/13/2010'
I get data exactly between those dates.
 
What was the wrong I was doing in retrieving data programatically?
 
Any help is appreciated. Thank you

Answers (6)