 |
|
 |
|
|
 |
Simple SQL statement and request.querystring |
 |
 |
|
|
|
|
 |
Re: Simple SQL statement and request.querystring |
 |
 |
|
|
 |
|
 |
|
|
 |
Re: Simple SQL statement and request.querystring |
 |
 |
|
|
06-20-06 06:23 PM
gjoneshtfc@volcanomail.com wrote:
> Hello, I have a simple problem that I just cannot get my head around!
>
> I currently have the following line in my ASP recordset:
>
> Recordset1.Source = "SELECT * FROM MainTable ORDER BY Price ASC"
Do you really need ALL the fields and ALL the rows?
>
> I have the following code at the start of the recordset:
>
> dim chosencar
> chosencar=Request.QueryString("make")
>
> What i want to have is a WHERE command in the SQL statement which will
> filter the passed value from the previous page. For example:
>
> Recordset1.Source = "SELECT * FROM MainTable WHERE
> Make='<--chosencar-->' ORDER BY Price ASC"
>
> Is there any way of doing what i want it to do please? I am a newbie
> at SQL so all help is greatly appreciated. Keeping it as simple as
> possible will also help me!
>
I would start by getting rid of the * and explicitly naming the fields
you wish the query to return. Then:
dim sql, arParms, make, cmd
make=Request.QueryString("make")
'validate make - make sure it contains what it's supposed to contain
'if it's valid, then:
sql="SELECT <list of fields> FROM MainTable " & _
"WHERE Make=? ORDER BY Price ASC"
'see the "?" That's called a parameter marker. You can
'have as many as you need. Now let's use a command object
'to pass a value to that parameter:
arParms=array(make) 'an array is required
set cmd=createobject("adodb.commmand")
with cmd
.commandtype=1 'adCmdText
.commandtext=sql
set .activeconnection=objconn
set Recordset1 = .Execute(,arParms)
End With
if not Recordset1.eof then ...
You can find the ADO documentation here:
http://msdn.microsoft.com/library/e...pireference.asp
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Simple SQL statement and request.querystring |
 |
 |
|
 |  |  |  |  |
 |
 |
|
gjoneshtfc@volcanomail.com |
|
|
 |
 |


 |
 |
 |
|  |  |  |  |
|
06-21-06 06:21 PM
Thanks Aaron,
I tried what you suggested but it says the syntax is incorrect. Any
other suggestions on how to do it? I a complete novice to SQL so
parameterized queries and stored procedures are things i have not heard
of!
Thanks again for your reply,
Regards, Gareth
Aaron Bertrand [SQL Server MVP] wrote:[vbcol=seagreen]
> Well, aside from various bad things I might point out (like NEVER USE SELE
CT
> * IN PRODUCTION CODE), have you tried:
>
> chosencar = Replace(Request.QueryString("make"), "'", "''")
> Recordset1.Source = "SELECT * FROM MainTable WHERE " & _
> " [make] = '" & chosencar & "' ORDER BY Price ASC"
>
> Also, consider parameterized queries, stored procedures, etc. Constructin
g
> ad hoc sql in this way is very dangerous and inefficient. I wish I wasn't
> too lazy to look up the links usually provided by Bob Barrows, but he's no
t.
> :-)
>
>
>
>
>
> <gjoneshtfc@volcanomail.com> wrote in message
> news:1150825931.393290.315630@u72g2000cwu.googlegroups.com...
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Simple SQL statement and request.querystring |
 |
 |
|
|
 |
|
 |
|
|
 |
Re: Simple SQL statement and request.querystring |
 |
 |
|
|
 |
|
 |
|
|
 |
Re: Simple SQL statement and request.querystring |
 |
 |
|
|
 |
|
 |
|
|
 |
Re: Simple SQL statement and request.querystring |
 |
 |
|
|
06-21-06 06:21 PM
gjoneshtfc@volcanomail.com wrote:
> Thanks for your help Bob,
>
> Just one query with what you have written - how do i link that in with
> the VBScript Recordset1.Source?
You don't need to. Setting the Source property to a sql statement and
opening the recordset achieves the same result as executing the sql
statement using the Command object.
Why am I recommending the Command object? or better yet stored procedures?
SQL Injection:
http://mvp.unixwiz.net/techtips/sql-injection.html
http://www.sqlsecurity.com/DesktopDefault.aspx?tabid=23
Since you did not tell us what type of database you are using, I will
refrain from posting the links that explain how to use stored procedures.
Here's my canned post about using Command objects:
http://groups-beta.google.com/group...r />
2fee7804e
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Simple SQL statement and request.querystring |
 |
 |
|
|
|
|
 |
Re: Simple SQL statement and request.querystring |
 |
 |
|
|
|
|
|
Sponsored Links |
 |
 |
|
|
 |
All times are GMT. The time now is 12:48 PM. |
 |
|
|
 |
|
 |
|
|
 |
|
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
|
|
|
|
Medical and Health forum | Computer Games Reviews | Graphics design forum
|
 |
|
 |
|