473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

SQL statement won't recognize variable

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

Nov 19 '05 #1
2 957
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 & "#)"

"Chumley Walrus" <sp*******@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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


Nov 19 '05 #2
Thanks. I see now how T-sql disassociates itself from certain non-sql
elements.

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

94
by: John Bailo | last post by:
The c# *return* statement has been bothering me the past few months. I don't like the fact that you can have different code paths in a method and have multiple return statements. To me, it...
10
by: ale.of.ginger | last post by:
Greetings! I am trying to make a multiplayer (no AI, 2 person) game of tic tac toe in Python. So far it has been pretty simple. My only concern is with the win checking to see if a person has...
81
by: candy | last post by:
hi all, Is there is any way in the C language by which I can get the address of a statement? For eg,consider the following simple program: 1. #include<stdio.h> 2. 3. int main(void){ 4. ...
5
by: Wing | last post by:
Hi all, I am writing a function that can change the value "Quantity" in the selected row of MS SQL table "shoppingCart", my code is showing below ...
6
by: tshad | last post by:
In my User control, I tried to do this: *************************************************************************** <Script runat="server"> Public ClientName As String = "<!-- #include file =...
35
by: Thierry Loiseau | last post by:
Hello all, and Happy end year 2005 ! Well, I would like to obtain a list of all JavaScript var statement, With "for...in" perharps ? That is bellow my recent test here, but the problem is...
9
by: David Veeneman | last post by:
I'm just getting started with ASP.NET, using VS 2005. As an exercise, I opened the root web site in VS 2005 and created a simple welcome page. I saved the page as Default.aspx and made sure that...
2
by: Etayki | last post by:
Hello, I am trying to create an IF statement that will recognize whether or not a field in the database table is set to some value or if is NULL. Dim myCommand As New...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.