|
 |
asp_databases thread: SQL WHERE Inquiry
Message #1 by "Dick May" <rmay@t...> on Wed, 26 Apr 2000 21:45:31
|
|
Hello.
Within an .asp file with VBScript, attempting (via ADO connection) an SQL
Select with WHERE operand. Hardcoding a variable (as documented in the ASP
2.0 wrox book sample code, as well as in other SQL books) such as WHERE
Name = 'John Doe' " works fine; however, I cannot find any SQL Select
sample using the WHERE option that uses a variable such as received via a
Form.Request object. I have unsuccessfully tried several SQL "Select
WHERE" option scenarios including:
WHERE Name = Request.Form("cName") "
WHERE Name = 'Request.Form("cName")' "
WHERE Name = Request.Form(Item) "
WHERE Name = 'Request.Form(Item)' "
WHERE Name = <% = Request.Form("cName") %> "
WHERE Name = '<% = Request.Form("cName") %>' "
Note, cName is a valid name of my input text box within a <FORM with
Method=POST. And again, hardcoding the variable... WHERE Name = 'John Doe'
" works as expected and the SQL query is successfully executed. Also if
using strName = Request.Form("cName"), any of the following:
WHERE Name = 'strName' "
WHERE Name = strName "
WHERE Name = <% = strName %> "
WHERE Name = '<% = strName %>' "
are not successful as well.
Thank you.
Message #2 by =?iso-8859-1?Q?=C1rni_B=2E_Halld=F3rsson?= <abh@t...> on Thu, 27 Apr 2000 10:14:48 -0000
|
|
Hi
SQL needs ' surrounding the value in the where clause, example:
WHERE Name =3D '" & Request.Form("cName") & "'"
Regards
Arni B. Halldorsson
abh@t...
-----Original Message-----
From: Dick May
Sent: 26. apr=EDl 2000 21:46
To: ASP Databases
Subject: [asp_databases] SQL WHERE Inquiry
Hello.
Within an .asp file with VBScript, attempting (via ADO connection) an
SQL
Select with WHERE operand. Hardcoding a variable (as documented in the
ASP
2.0 wrox book sample code, as well as in other SQL books) such as WHERE
Name =3D 'John Doe' " works fine; however, I cannot find any SQL Select
sample using the WHERE option that uses a variable such as received via
a
Form.Request object. I have unsuccessfully tried several SQL "Select
WHERE" option scenarios including:
WHERE Name =3D Request.Form("cName") "
WHERE Name =3D 'Request.Form("cName")' "
WHERE Name =3D Request.Form(Item) "
WHERE Name =3D 'Request.Form(Item)' "
WHERE Name =3D <% =3D Request.Form("cName") %> "
WHERE Name =3D '<% =3D Request.Form("cName") %>' "
Note, cName is a valid name of my input text box within a <FORM with
Method=3DPOST. And again, hardcoding the variable... WHERE Name =3D
'John Doe'
" works as expected and the SQL query is successfully executed. Also
if
using strName =3D Request.Form("cName"), any of the following:
WHERE Name =3D 'strName' "
WHERE Name =3D strName "
WHERE Name =3D <% =3D strName %> "
WHERE Name =3D '<% =3D strName %>' "
are not successful as well.
Thank you.
---
You are currently subscribed to asp_databases
$subst('Email.Unsub')
Message #3 by "Uday Hargewar" <udaykh@h...> on Thu, 27 Apr 2000 13:03:39 GMT
|
|
I think request.form or strName are not a part of SQL statement. They belong
to ASP code. So, these variables should be enclosed in <% and %> tags with
no "=".
I think this should work.
strSQL = "Select * from " & <%session("strTableName")%> & " where name = '"
& <%request.form("cName")%> & "'"
From: "Dick May"
Reply-To: "ASP Databases" <asp_databases@p...>
To: "ASP Databases" <asp_databases@p...>
Subject: [asp_databases] SQL WHERE Inquiry
Date: Wed, 26 Apr 2000 21:45:31
Hello.
Within an .asp file with VBScript, attempting (via ADO connection) an SQL
Select with WHERE operand. Hardcoding a variable (as documented in the ASP
2.0 wrox book sample code, as well as in other SQL books) such as WHERE
Name = 'John Doe' " works fine; however, I cannot find any SQL Select
sample using the WHERE option that uses a variable such as received via a
Form.Request object. I have unsuccessfully tried several SQL "Select
WHERE" option scenarios including:
WHERE Name = Request.Form("cName") "
WHERE Name = 'Request.Form("cName")' "
WHERE Name = Request.Form(Item) "
WHERE Name = 'Request.Form(Item)' "
WHERE Name = <% = Request.Form("cName") %> "
WHERE Name = '<% = Request.Form("cName") %>' "
Note, cName is a valid name of my input text box within a <FORM with
Method=POST. And again, hardcoding the variable... WHERE Name = 'John Doe'
" works as expected and the SQL query is successfully executed. Also if
using strName = Request.Form("cName"), any of the following:
WHERE Name = 'strName' "
WHERE Name = strName "
WHERE Name = <% = strName %> "
WHERE Name = '<% = strName %>' "
are not successful as well.
Thank you.
Message #4 by Daniel Walker <danielw@w...> on Thu, 27 Apr 2000 14:19:50 +0100
|
|
Erm, sort of correct, but the use of <% and %> is wrong. The SQL statement
already occupies a block of script, and so the Request cannot (and should
not) be further compartmentalised. As Anri Halldorsson said earlier, the key
is to concatenate the string, rather than putting the request statement in
the string (where it gets interpreted as text)
Daniel Walker
Wrox Press
PROGRAMMER TO PROGRAMMER TM
www.wroxconferences.com
www.wrox.com
wwww.asptoday.com
-----Original Message-----
From: Uday Hargewar
Sent: Thursday, April 27, 2000 14:04
To: ASP Databases
Subject: [asp_databases] Re: SQL WHERE Inquiry
I think request.form or strName are not a part of SQL statement. They belong
to ASP code. So, these variables should be enclosed in <% and %> tags with
no "=".
I think this should work.
strSQL = "Select * from " & <%session("strTableName")%> & " where name = '"
& <%request.form("cName")%> & "'"
From: "Dick May"
Reply-To: "ASP Databases" <asp_databases@p...>
To: "ASP Databases" <asp_databases@p...>
Subject: [asp_databases] SQL WHERE Inquiry
Date: Wed, 26 Apr 2000 21:45:31
Hello.
Within an .asp file with VBScript, attempting (via ADO connection) an SQL
Select with WHERE operand. Hardcoding a variable (as documented in the ASP
2.0 wrox book sample code, as well as in other SQL books) such as WHERE
Name = 'John Doe' " works fine; however, I cannot find any SQL Select
sample using the WHERE option that uses a variable such as received via a
Form.Request object. I have unsuccessfully tried several SQL "Select
WHERE" option scenarios including:
WHERE Name = Request.Form("cName") "
WHERE Name = 'Request.Form("cName")' "
WHERE Name = Request.Form(Item) "
WHERE Name = 'Request.Form(Item)' "
WHERE Name = <% = Request.Form("cName") %> "
WHERE Name = '<% = Request.Form("cName") %>' "
Note, cName is a valid name of my input text box within a <FORM with
Method=POST. And again, hardcoding the variable... WHERE Name = 'John Doe'
" works as expected and the SQL query is successfully executed. Also if
using strName = Request.Form("cName"), any of the following:
WHERE Name = 'strName' "
WHERE Name = strName "
WHERE Name = <% = strName %> "
WHERE Name = '<% = strName %>' "
are not successful as well.
Thank you.
---
You are currently subscribed to asp_databases
Message #5 by "Dick May" <rmay@t...> on Thu, 27 Apr 2000 15:12:24
|
|
Arni,
Thank you. Your recommendation worked as you expected.
|
|
 |