SQL statement won't recognize variable

C

Chumley Walrus

I'm trying to declare a variable (datetime data type), and insert that
value in the where clause of an SQL statement (I'm using MS Access db
with oledb classes) in an aspx page using vb.net:

dim todd = DateTime.Today.ToString ( "d" )
Dim strSQL as string ="SELECT article, articleheader, articleID
FROM articles WHERE (dept = 'news') AND (articledate = #<%=todd%>#)"

...it gives me Syntax error in date in query expression '(dept = 'news')
AND (articledate = #<%=todd%>#)'.

...the same with #'todd'#

using: (articledate = #4/21/2005#) works

chumley
 
K

Ken Cox [Microsoft MVP]

I would think the syntax would be more like this:

dim todd = DateTime.Today.ToString ( "d" )
Dim strSQL as string ="SELECT article, articleheader, articleID
FROM articles WHERE (dept = 'news') AND (articledate = #" & todd & "#)"
 
C

Chumley Walrus

Thanks. I see now how T-sql disassociates itself from certain non-sql
elements.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top