Bullschmidt.com
Home
Web Database Concept
How We Work Together
Bio
Web Database Sample
Classic ASP Design Tips
Bar Chart Tool
Web Design Resources
Access Database Sample
Classic ASP Design Tips
QueryString
These are opinions of J. Paul Schmidt, MBA.
No warranties are either expressed or implied.
To Use Paul's Services:
Paul@Bullschmidt.com
Example URL with a querystring:
http://www.mysite.com/mypg.asp?InvID=1074
And this can be built into a link for each record in a recordset like this:
<a href="http://www.mysite.com/mypage?InvID=<%= objRS("InvID") %>">objRS("InvID")</a>
Because a variable might contain some odd characters like spaces, it's usually a good idea to use Server.URLEncode() when creating a querystring from a variable although it's not actually needed if the variable is a number. Thus the previous link would now be done like this:
<a href="http://www.mysite.com/mypage?InvID=<%= Server.URLEncode(objRS("InvID")) %>">objRS("InvID")</a>
And in the page that is opened you can use Request.QueryString("InvID") to get the value of InvID.
InvID = Request.QueryString("InvID")
And then create a SQL statement:
' Set strSQL.
strSQL = "SELECT * FROM MyTable WHERE InvID=" & InvID
Or if InvID is a text field in the underlying database as opposed to a numeric field, then some single quotes are needed too (and note that the ='" is an equals sign, single quote, and then a double quote and note that the final "'" is a double quote, single quote, and then another double quote):
' Set strSQL.
strSQL = "SELECT * FROM MyTable WHERE InvID='" & InvID & "'"
And to see something like this in action you can do the following:
- Go to
www.bullschmidt.com/login.asp
(the ASP Web database demo's login page)
- Click the Continue button
- On the Main Menu click the Invoices Edit button
- On the Invoices Edit Search Dialog click the Edit button
- On the Invoices Many page notice that each invoice number link includes a querystring such as ?InvID=1074
- Click on any invoice number
- On the Invoices Input page notice that the Web address includes the same querystring
To Use Paul's Services:
Paul@Bullschmidt.com
Copyright © 2000-2008
J. Paul Schmidt, MBA
Freelance Web and Database Developer
All Rights Reserved
Privacy Policy