Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help me find my mistake in this short code 2

Status
Not open for further replies.

mrkyn

MIS
Jan 30, 2002
78
US
Please help me to find my mistake in this short piece of code.

Dim rsItems
catnumber = CLng(Request.Querystring)
strSQL = "SELECT * FROM Item " & _
"WHERE ExpirationDate >= #" & FormatDateTime(Now,2) & "# " & _
"AND CatID = catnumber " & _
"AND ItemStatus = 'Active' ;"
Set rsItems = Server.CreateObject("ADODB.Recordset")
rsItems.Open strSQL, objConn

When I take away

"AND CatID = catnumber " & _

it work perfect. Otherwise the error message is on line

rsItems.Open strSQL, objConn:
"No value given for one or more required parameters". The database is OK.

Thanks!
 
Hi...
as you have mentioned, the problem is exactly catnumber
because, in your code, you have :
catnumber = CLng(Request.Querystring)
and this is wrong.
you have to specify the name of the querystring variable.
for example if you have a variable named "myVar" then you will have :
catnumber = CLng(Request.Querystring("myVar"))
but, bynow, you have not specify any variable then catnumber will be empty.

----
TNX.
E.T.
 
You will notice the other problem if you print the resulting SQL statement to the screen rather than sending it to the db. Instead of inserting the value of your catnumber variable into the statement you have inserted the word catnumber, so the database is (futiley) trying to find a value for catnumber and then replying back that it can't execute the statement because "catnumber" is unknown and can't be resolved.

That line should look like:
Code:
"AND CatID = " & catnumber & " " & _

-Tarwn

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Tarwn and ehsant, thank you very much for your responses. You helped me solve my problem. Thanks a lot. Ehsant, I have only one data in querystring. My link is ‘BrowseListings.asp?7’, and my CLng(Request.Queristring) returns the number 7. I am not sure, but I suppose I would need CLng(Request.Queristring(“MyVar”)) for the link ‘BrowseListings.asp?MyVar=7’.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top