About Robert D. Fahey Expertise I have been proramming in VB for 5 years, and 2 with ASP. I have a solid understanding of ASP and can answer questions from beginner to intermediate. I will consider student projects for money if needed.
Experience 2 years
Organizations AITP - Association of Information Technology Professionals
Education/Credentials BS in IT
Client/Server Application Development - Certification
Expert: Robert D. Fahey Date: 5/19/2003 Subject: Newbie to ASP coding(Part #2...Revised???).....
Question Mr. Fahey,
I just sent you an email regarding my ASP problem. I do have an ASP book to refer to, and I think I am starting to "Crawl" my way to a resolution...still need your help if possible.
1. I pass a variable from an .htm page to an .asp page which will be used to determine which table to open/view via the recordset object "objRS."
2. I use a Select Case statement to read the variable passed in the form of Request.QueryString("section").
3. The value obtained via the Select Case Request.QueryString("section") determines the actual table name I will use in the opening of the table via the "objRS.Open" statement I have in the below code(I believe the objRS.Open statement is incorrect somehow, but I haven't figured it out yet...looking for suggestions):
<%
Dim objConn, objRS
Dim adOpenForwardOnly, adLockReadOnly, adCmdTable
Set objConn = Server.CreateObject("ADODB.Connection") ' Set DB Connection Object/Variable
Set objRS = Server.CreateObject ("ADODB.Recordset") ' Set Recordset Object/Variable
objConn.Open "DSN=mysystemdsn;UID=myuid;PWD=mypwd" ' Set System Datasource Name
Select Case Request.QueryString("section")
Case "about" objRS.tablename = "about_hwc"
Case "acad" objRS.tablename = "hwc_academics"
Case "admit" objRS.tablename = "hwc_admissions"
Case "cat" objRS.tablename = "hwc_catalog"
Case "dir" objRS.tablename = "hwc_directory"
Case "faid" objRS.tablename = "hwc_faid"
Case Else Response.Write "Error"
End Select
objRS.Open "objRS.tableneme", objConn, adOpenForwardOnly, adLockReadOnly, adCmdTable 'now open it
While Not objRS.EOF 'Now loop through the records
Response.Write objRS("navtitle") & ", "
objRS.MoveNext
Wend
objRS.Close 'now close it
objConn.Close
Set objRS = Nothing '...and clean up
Set objConn = Nothing
%>
Answer Dennis,
Ok, you fixed the first problem that I saw with your old code, the Set objTable = Server.CreateObject("MyTable.Table")....that will definately throw an error. By the looks of it, you just want to grab a table name and use it based on what the value is in the QueryString object, correct?
If so, you're on the right track, but your Select Case Statement needs modifying and I've added a new variable to your list. Check this out:
<%
Dim objConn, objRS
Dim adOpenForwardOnly, adLockReadOnly, adCmdTable
Dim strTableName ‘NEW
Set objConn = Server.CreateObject("ADODB.Connection") ' Set DB Connection Object/Variable
Set objRS = Server.CreateObject ("ADODB.Recordset") ' Set Recordset Object/Variable
objConn.Open "DSN=mysystemdsn;UID=myuid;PWD=mypwd" ' Set System Datasource Name
‘NEW
Select Case Request.QueryString("section")
Case "about"
strTableName = "about_hwc"
Case "acad"
strTableName = "hwc_academics"
Case "admit"
strTableName = "hwc_admissions"
Case "cat"
strTableName = "hwc_catalog"
Case "dir"
strTableName = "hwc_directory"
Case "faid"
strTableName = "hwc_faid"
Case Else
Response.Write "Error"
End Select
objRS.Open strTableName, objConn, adOpenForwardOnly, adLockReadOnly, adCmdTable 'now open it
While Not objRS.EOF 'Now loop through the records
Response.Write objRS("navtitle") & ", "
objRS.MoveNext
Wend
objRS.Close 'now close it
objConn.Close
Set objRS = Nothing '...and clean up
Set objConn = Nothing
%>
You could add the adovbs.inc as an include file, it comes from Microsoft and gives you ALL the ADO named constants to use. If you want to use it, simply add the following code to the top of your ASP page, this will "include" the file in your page:
<!-- #INCLUDE file="adovbs.inc" -->
If you want, here is the contents of adovbs.inc, you can put this into any file and save it as adovbs.inc and it will work:
<%
'--------------------------------------------------------------------
' Microsoft ADO
'
' (c) 1996-1998 Microsoft Corporation. All Rights Reserved.
'
'
'
' ADO constants include file for VBScript
'
'--------------------------------------------------------------------