ADO and SELECTing dates

ADO and SELECTing dates

Post by Spud_Monke » Fri, 23 Jan 2004 18:06:46


Can anyone help

I am trying to perform a select query from within VB connecting to a SQL
Server 2000 database.

I am trying to select and in the where clause i want to search for a date.
The field 'MyField' in the database is set up as a datetime data type.

See code below.
---
dim rs as recordset
dim con
dim sqstring

con.Open = "Provider=SQLOLEDB.1;Data Source=(local);Initial
Catalog=MyDatabase;user id = 'sa';password='sa'"

sqlstring = "Select MyField from MyTable where MyField = '01/01/2004' "

rs.Open sqlstring, con, 1
----
I have also tried various other variations on how to represent the date
Nothing is coming back and there definately is data for the date. What is
the syntax for searcing for datetime data types through ADO?
 
 
 

ADO and SELECTing dates

Post by Veig » Sat, 24 Jan 2004 01:49:22

Try;
"SELECT MyField FROM MyTable WHERE MyField = #01/01/2004# "

--
Chris Hanscom
MVP (Visual Basic)
http://www.yqcomputer.com/
Application Design Section
http://www.yqcomputer.com/
------