date issues..

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi..i have a sql command which i would like to execute in order to calculate the salesman actual sales on a monthly basis such as below so that i would be able to generate a graph based on their actual sales and targeted sales.

select sum(total) as total from Orders where emp_no = 1 and order_date between '07-01-2004' and '07-31-2004'

the problem is, how should i put the above sql statement into the sqlcommand on my web service?i've tried the following way but it couldn't work.can anyone pls help?? thanks.

Dim dtf As String
dtf = "MM'-'dd'-'yyyy hh':'mm':'ss"

Public Function calActual(ByVal empno As Integer, _
ByVal startDate As DateTime, _
ByVal endDate As DateTime) As DataSet


Dim cm As New SqlCommand("SELECT sum(total) As totalsales FROM Orders " & _
"WHERE emp_no = @emp_no AND order_date " & _
"BETWEEN @order_date AND @order_date ", cn)
cm.Parameters.Add("@emp_no", empno)
cm.Parameters.Add("@orderDate", startDate.ToString(dtf))
cm.Parameters.Add("@orderDate", endDate.ToString(dtf))
 
chris said:
hi..i have a sql command which i would like to execute in order to
calculate the salesman actual sales on a monthly basis such as below
so that i would be able to generate a graph based on their actual
sales and targeted sales.

select sum(total) as total from Orders where emp_no = 1 and
order_date between '07-01-2004' and '07-31-2004'

the problem is, how should i put the above sql statement into the
sqlcommand on my web service?i've tried the following way but it
couldn't work.can anyone pls help?? thanks.

Don't put the value directly in the SQL - use parameters.

See http://www.pobox.com/~skeet/csharp/faq/#db.parameters
 
Back
Top