SQL Server Date comparison Problem

JimStewart

Member
Joined
Oct 8, 2010
Messages
19
Programming Experience
Beginner
Ok
I have a hosted SQL server 2008 that I am using for an update server for a product catalog. The products table has a column DateModified (dateType) for each product (row)

The application uses a local Access 2003 table that contains a table that stores the last date (also dateType) the appilication was updated.

the SQL that is producing the errors is as follows:


Dim SQL As String = "SELECT * FROM Products WHERE DateModified < " & (lastDate.Date) ' lastDate is the variable that contains the local date


in which I am getting the error "Operand Clash: Date type is not compatible with int"

I have been searching, without much success, as to how to compare the two dates?

Any suggestion?


Thanks in advance
 
Never use String concatenation to insert variables into SQL statements. Always use parameters. Follow the Blog link in my signature and check out my post on ADO.NET Parameters.
 
[Solved] Date comparison problem

Thanks Again jmcilhinney, I changed the code to:
VB.NET:
 Dim SQL As String = "SELECT * FROM Products WHERE DateModified < @LastDateModified"

                    Dim myCommand As New SqlCommand(SQL)
                    With myCommand.Parameters
                        .AddWithValue("@LastDateModified", lastDate.Date)
                    End With

And it worked great. Thanks!
 
Back
Top