SQL statement won't recognize variable

  • Thread starter Thread starter Chumley Walrus
  • Start date Start date
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
 
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 & "#)"
 

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

Back
Top