I am having a problem with my VBscript while interacting with an SQL database.
I have created two classes in vbs, one which is basically a wrapper for all of the database objects and the other an object that outputs HTML code to a web browser.
When I make a query to the database, I do it with a function of the database class, here is the function (within the class):
class database
private conn
private rs
private sql
'=========================
'CONSTRUCTORS/DESTRUCTORS
'=========================
private sub class_initialize()
set conn = server.createObject("ADODB.Connection")
conn.ConnectionTimeout = 30
conn.CommandTimeout = 30
conn.open Application ("WebConn")
end sub
private sub class_terminate()
conn.close
end sub
public function setString(str)
sql = str
end function
public function execQuery()
set execQuery = conn.execute(sql)
end function
end class
I use the object in my main like this:
dim rs
dim db
set db = new database
db.setString("SELECT * FROM hyperlink " _
+ "WHERE hyperlinkID=" & linkID)
set rs = db.execQuery()
when I try to access the records in the record set, here is what I do:
response.write ("SOURCE: " + rs(3) + "<br>")
response.write ("DESCRIPTION: " + rs(2) + "<br>")
NOW FOR THE WEIRD STUFF:
which ever attribute I try first (either index 2 or 3) only the first of the two print, so either the SOURCE or the DESCRIPTION, but never both at the same time, I have to comment the first out to print the second, so if I were to switch the indexes above, the DESCRIPTION would print, and the SOURCE would not, but when I comment out the DESCRIPTION when the index is switched to 2,3, the SOURCE will print.
What have I done incorrectly??
Then, when I pass the rs into a sub routine of the webpage object for the "real" output to the browser, I can never print the description, no matter what. This leads me to believe that I have some type of casting problem, but again, I am unsure.
I do the passing like this:
dim page
page = new webpage
page.modifyLinkForm rs
here is the function:
public sub modifyLinkForm(rs)
dim title
dim link
dim source
dim description
title = rs(1)
link = rs(4)
source = rs(3)
description = rs(2)
'=======================================================
'DEBUGGING
'response.write("TITLE: " + title + "<br>")
'response.write("LINK: " + link + "<br>")
'response.write("SOURCE: " + source + "<br>")
'response.write("DESCRIPTION: " + description + "<br>")
'=======================================================
end sub
what have I done wrong???
thanks,
--Bryan
I have created two classes in vbs, one which is basically a wrapper for all of the database objects and the other an object that outputs HTML code to a web browser.
When I make a query to the database, I do it with a function of the database class, here is the function (within the class):
class database
private conn
private rs
private sql
'=========================
'CONSTRUCTORS/DESTRUCTORS
'=========================
private sub class_initialize()
set conn = server.createObject("ADODB.Connection")
conn.ConnectionTimeout = 30
conn.CommandTimeout = 30
conn.open Application ("WebConn")
end sub
private sub class_terminate()
conn.close
end sub
public function setString(str)
sql = str
end function
public function execQuery()
set execQuery = conn.execute(sql)
end function
end class
I use the object in my main like this:
dim rs
dim db
set db = new database
db.setString("SELECT * FROM hyperlink " _
+ "WHERE hyperlinkID=" & linkID)
set rs = db.execQuery()
when I try to access the records in the record set, here is what I do:
response.write ("SOURCE: " + rs(3) + "<br>")
response.write ("DESCRIPTION: " + rs(2) + "<br>")
NOW FOR THE WEIRD STUFF:
which ever attribute I try first (either index 2 or 3) only the first of the two print, so either the SOURCE or the DESCRIPTION, but never both at the same time, I have to comment the first out to print the second, so if I were to switch the indexes above, the DESCRIPTION would print, and the SOURCE would not, but when I comment out the DESCRIPTION when the index is switched to 2,3, the SOURCE will print.
What have I done incorrectly??
Then, when I pass the rs into a sub routine of the webpage object for the "real" output to the browser, I can never print the description, no matter what. This leads me to believe that I have some type of casting problem, but again, I am unsure.
I do the passing like this:
dim page
page = new webpage
page.modifyLinkForm rs
here is the function:
public sub modifyLinkForm(rs)
dim title
dim link
dim source
dim description
title = rs(1)
link = rs(4)
source = rs(3)
description = rs(2)
'=======================================================
'DEBUGGING
'response.write("TITLE: " + title + "<br>")
'response.write("LINK: " + link + "<br>")
'response.write("SOURCE: " + source + "<br>")
'response.write("DESCRIPTION: " + description + "<br>")
'=======================================================
end sub
what have I done wrong???
thanks,
--Bryan