SELECT values between two selected DATES

Hi, was wondering if someone can help me, I trying to extract values from a database, but dates beween, 2 certain dates.

But, somehow, the values that's displayed, aren't the correct values.

I'm using access2003, with VB.NET. the data type af the 'adddate'-column are "date/time", and I'm using a DateTimePicker to alloy the user to select their own 2 dates.

this is the SELECT statement,

Dim comm As New OleDb.OleDbCommand("SELECT * from labour where adddate between " & fromdate & " AND " & todate, conn)

but easch time I try to run it, I get an error message, stating that "Missing operator

If someone can see something I'm not, please direct me.

Thanks

SJB



Answer this question

SELECT values between two selected DATES

  • CoderX

    Hi!

    You better use SQL parameters:

    "SELECT * FROM labour WHERE addDate BETWEEN @FromDate AND @ToDate"

    then you must add parameters @FromDate and @ToDate:

    comm.Parameters.AddWithValue("@FromDate", fromDate)

    comm.Parameters.AddWithValue("@ToDate", toDate)

    This is better because you don't need to care about dates to string formatting and parameters defend your code from SQL injection attacks.



  • SELECT values between two selected DATES