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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT from db based on number / ID

Status
Not open for further replies.

LEICJDN1

Technical User
Nov 27, 2002
201
GB
I need to select a recordset by ID number.

Had planned on doing this by sending the ID as a querystring from the requesting link.

Then something like this:

Code:
deltarget=Request.Querystring
"SELECT * FROM reftable WHERE ID=" & deltarget & "'"

But this errors out. I guess it is because the ID integer pulled onthe previous page is sent as a 'string' so conflicting with the ID field being autonumber in the db.

Is there a way to turn the string back into an integer to use in the SQL statement or is my SQL statement at fault?

Thanks again.

 
You're not delimiting your string correctly - you have an apostrophe at the end but not directly after ID= in your SQL.
 
You need to specify the name of the QueryString item whose value you are trying to read. It is also worth converting it to an Int if it is a number you are sending.
Code:
deltarget= CInt(Request.Querystring("deltarget"))

strSQL = "SELECT * FROM reftable WHERE ID=" & deltarget & "';"

Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
You haven't specified that the querystring is called - i.e.

deltarget = Request.QueryString("ID")
 
Try this:

A small change to what tony suggested-

deltarget= CInt(Request.Querystring("deltarget"))

strSQL = "SELECT * FROM reftable WHERE ID="&deltarget


VJ
 
Thanks all - suprised by the flood of responses.

You were kinda all right - managed to work though the suggestions and ended up with this amalgamation that works just fine:

Code:
deltarget=CInt(Request.Querystring)
"SELECT * FROM reftable WHERE ID=" & deltarget & ";"

This is turning the querystring into an integer then matching that to the ID delivering the relevant recordset nicely.

Cheers..
 
How come

deltarget=CInt(Request.Querystring)

the above line works??


VJ

 
Don't know!
Tried the version given but gave an error.
Changed it to the above and it works fine.
 
The Querystring name of "deltarget" that I stated was an example. What is the name of the querystring item you use? Did you substitute my example name for your actual name?

How are you passing the querystring to this page from the previous page?

Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
The querystring is just a number - there is only one so I did not bother with a name.
The referring link looks like thie something.asp?4 for example.

Sorry for the confusion - I see know that if the querystring was named then your example would work fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top