Problem with Data adapter sql statement

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

Guest

I am accessing a MS SQL2000 database. The table has a date field setup as 'Datetime' I then setup a data adapter (VB.Net, windows) as follows
daEmpDiv = New SqlClient.SqlDataAdapter("SELECT EmployeeID, DivisionID, SubDivision_ID FROM tblEmpDivisionDates WHERE EmployeeID = 17 AND Start_Date <= " & Today(), conn

When done no records are retrieved, but when I remove the start_date condition the records are retrieved. I know that I am missing something simple, but I unable to see it. Any help would be greatly appreciated

Thanks, JR :)
 
Change it to Start_Date <= GetDate()
JR said:
I am accessing a MS SQL2000 database. The table has a date field setup as
'Datetime' I then setup a data adapter (VB.Net, windows) as follows:
daEmpDiv = New SqlClient.SqlDataAdapter("SELECT EmployeeID, DivisionID,
SubDivision_ID FROM tblEmpDivisionDates WHERE EmployeeID = 17 AND Start_Date
<= " & Today(), conn)
When done no records are retrieved, but when I remove the start_date
condition the records are retrieved. I know that I am missing something
simple, but I unable to see it. Any help would be greatly appreciated.
 
JR said:
I am accessing a MS SQL2000 database. The table has a date field
setup as 'Datetime' I then setup a data adapter (VB.Net, windows) as
follows:
daEmpDiv = New SqlClient.SqlDataAdapter("SELECT EmployeeID,
DivisionID, SubDivision_ID FROM tblEmpDivisionDates WHERE EmployeeID
= 17 AND Start_Date <= " & Today(), conn)

When done no records are retrieved, but when I remove the start_date
condition the records are retrieved. I know that I am missing
something simple, but I unable to see it. Any help would be greatly
appreciated.

Instead of embedding the date directly in the SQL, use a parameter and
set the value of that parameter to today's date. That way you won't
need to worry about conversions and formatting, etc.
 
Back
Top