The following tutorial describes the creation of hyperlinks to the fields displayed using Getstring
For example, I might need to know the details of a company called "Laughing Lumberjack Lager" having a unique ID which is the primary key. So I display the name of the company as a hyperlink to a page and append the ID to the link. A bit confusing, so let me explain with an example.
Consider the following hyperlink: <a href="display.asp?id=67">Laughing Lumberjack Lager</a>. If a user clicks on the hyperlnk Laughing Lumberjack Lager, he will see all the required details about the company Laughing Lumberjack Lager displayed by the page display.asp. The ASP page display.asp would contain the code to displays the details for a particular company (specified by the ID passed through the QueryString). Within the page display.asp lies a line
<% ID = Request.QueryString("id") %>
Since I now possess the ID of the company, I can use it in my SQL query to obtain the company details!
Using GetString, we can create a list of hyperlinks from a database table! To display such a hyperlink-list, we only need to make a small change to the code we looked at in Part 1 (specifically the few lines of code around the call to GetString and the SQL string).
<%
Option Explicit
'Create the SQL query
Dim mySQL
mySQL="select FAQCategoryID, Name from tblFAQCategory order by Name"
'Create the Connection and execute the query.
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DSN=MyDSN"
Dim objRS
Set objRS = objConn.Execute(mySQL)
'Incase no records exist, have a handler to present a sweet message
'and call the subroutine CloseConn which closes the connection.
If objRS.eof then
Response.Write "Sorry, No records were found.<br>"
Call CloseConn
Response.End
End If
'This part of the code creates the various hyperlinks
'selected option for all companies.
Response.write("<a href=""display.asp?ID=")
Response.Write objRS.GetString(,,""">", _
"</a><br><a href=""display.asp?ID=", "-null-")
Response.Write("""></a>")
Call CloseConn 'Clean up!
' Sub to handle closing and cleaning up connections
Sub CloseConn
objRS.close
set objRS = Nothing
objConn.close
Set objConn = Nothing
End Sub
%>