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

Wierd database script.

Status
Not open for further replies.

bdina

Programmer
Jun 17, 2003
47
0
0
US
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 am having a problem seeing where you are having an issue..

If it is a casting issue as you suspect you could try repacing the + with a & when you concatinate the debug statement,

e.g. response.write ("SOURCE: " & rs(3) & "<br>")
response.write ("DESCRIPTION: " & rs(2) & "<br>")

The + will interpert a number as such and tell you you can't perform addition it to a string or just fail.

however what is wierd is that if you

response.write ("SOURCE: " + rs(3) + "<br>")
response.write ("DESCRIPTION: " + rs(2) + "<br>")

You would see SOURCE:XXXXXX
DESCRIPTION:

but if you jsut do
response.write ("DESCRIPTION: " + rs(2) + "<br>")

you would see DESCRIPTION: XXXXX

is that correct?

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top