Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 31st, 2006, 05:35 PM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default sql parameters

I'm trying to use sql parameters in classic asp (3.0) and keep running into a "Must declare the variable '@email'" error...

What I have...

...
email = Trim(request("email"))

sql = "SELECT * FROM tblUsers WHERE Email=@email"

Set conn = server.CreateObject("ADODB.Connection")
conn.open connection

Set cmd = server.CreateObject("ADODB.Command")
cmd.ActiveConnection = conn
cmd.CommandType = adCmdText
cmd.CommandText = psql
cmd.Parameters.Append cmd.CreateParameter ("@email", adVarChar, adParamInput, 50, email)

Set rs = server.CreateObject("ADODB.Recordset")
rs.CursorLocation = adUseClient
rs.LockType = adLockReadOnly

rs.Open cmd.Execute
...

Please let me know what I am doing wrong.

Thanks
 
Old April 1st, 2006, 11:59 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 189
Thanks: 0
Thanked 0 Times in 0 Posts
Default

...but what is @email...?

Med vennlig hilsen
grstad

 
Old April 3rd, 2006, 09:30 AM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The "@email" in the sql statement is my parameter value holder where I will later assign the value "email" to it using sql parameters.

That's what I want to do but I'm doing something wrong.

In asp.net you use the @ sign to denote a parameter value will be used. How do you do that in classic asp?

Thanks.
 
Old April 4th, 2006, 12:42 PM
Friend of Wrox
 
Join Date: May 2005
Posts: 189
Thanks: 0
Thanked 0 Times in 0 Posts
Default

...does the "@email" variable actually hold any value?
I am not familiar with .aspx, but it maight be recomended to declare the variable "@email".
In the moment the "@email" is interpreted, it does not hold any value.

Normally you also has to collect the value by;

Request.form("@email") or request.querystring("@email") or ....

It maight also be an issue that @ often is assigned values by the system. I am not sure.

So the bottom line must be; have you declared the variable and really assigned it any value...?

Med vennlig hilsen
grstad


 
Old April 7th, 2006, 11:16 AM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

"have you declared the variable and really assigned it to any value...?" -- Yes, that is my problem.

I'm trying to assign the sql placeholder @email using the line below:

cmd.Parameters.Append cmd.CreateParameter ("@email", adVarChar, adParamInput, 50, email)

That's what isn't working...

the var email = Trim(request("email")) (a form field) I tried hardcoding the email just for testing and it still doesn't work.

I guess a better question would be how do you use/implement sql parameters in asp 3.0?

Thanks.




 
Old April 12th, 2006, 05:21 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 189
Thanks: 0
Thanked 0 Times in 0 Posts
Default

... as far as I know, you have to code;

dim email 'which sets of memory for the name email to hold a value

...

email = Request.form("email") 'if your form says post
or
email = Request.querystring("email") 'if your form says get

...

sql = "SELECT * FROM tblUsers WHERE Email = '" & email & "'

' the variable email now holds the value from the form field and in your sql you says «open all from tabell users, where the field email holds the value of the form field email»

but according to your code in the fora, it looks as this is known to you?! I am not sure aboat the trim which removes any space from a string. It maight be better to place it somwhere else in your code. What about

dim email
email = trim(email)

this is as far as my knowledge goes. When it comes to the connection-object later in your code, I am not sure. I do leave the baton to the next reader...

Med vennlig hilsen
grstad

PS. The @email, I ask again, what is it? It do not hold any value and in the code it is read as a variable. Does it correspond to any scrip sending emails from within a script? Have you cut it out from somewhere? In the moment @email is read, it must have some






Similar Threads
Thread Thread Starter Forum Replies Last Post
Parameters from SQL to VBA Skan Access VBA 4 October 25th, 2007 06:53 AM
sql parameters not passed or received redeye2 Pro VB.NET 2002/2003 1 November 5th, 2004 07:10 PM
Custom SQL parameters sphair BOOK: Professional Crystal Reports for VS.NET 1 April 6th, 2004 11:52 PM
SQL output parameters ohiggs SQL Server 2000 4 February 9th, 2004 10:09 PM
parameters to sql psingh SQL Server 2000 3 June 26th, 2003 06:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.