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!

Weird SQL 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, this question is less an ASP question than a VB question so this is why I posted it in this forum.

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??

thanks,
--Bryan
 
Hello bdina,

[1] Take out the "on error resume next" server-side to see the error.
[2] Your construction of the class is not proper? Change the two properties settings like this.
[tt]
property get setString(str)
sql = str
end property

property get execQuery()
set execQuery = conn.execute(sql)
end property
[/tt]
regards - tsuji
 
Correction:

I meant:
[tt]property [red]let[/red] execQuery()
set execQuery = conn.execute(sql)
end property[/tt]

- tsuji
 
what is a property? will they be seen as private or public with respect to the class?? I am not too familiar with VBscript. Also, what does the "let" keyword do?

when I made the change to my code I got the following:


Microsoft VBScript compilation error '800a041e'

Property set or let must have at least one argument

/ptan/admin/includes/database.vbs, line 45

property let execQuery()
------------------------^

I am not sure this is what I want to do.

thanks,
--Bryan
 
bdina,

Sorry for the mistake. Switch between get and let! Also avoid execquery which is suspiciously reserved. Let say myexecquery. () is not necessay, if you like.
[tt]
property let setString(str)
sql = str
end property

property get myexecQuery
set myexecQuery = conn.execute(sql)
end property
[/tt]
- tsuji
 
bdina,

>I am not sure this is what I want to do.
Yes, it is fair enough. I am not sure this is what you want to do neither. Let me regroup all the statements so that you can assess yourself if it is what you want as an intermediate development stage.
Code:
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

   property let setString(str)
      sql = str
   end property

   property get myexecQuery
      set myexecQuery = conn.execute(sql)
   end property
end class
>I use the object in my main like this:
You then use the object like this:
[tt]
dim rs
dim db

set db = new database

db.setString = "SELECT * FROM hyperlink " _
+ "WHERE hyperlinkID=" & linkID)

set rs = db.myexecQuery
[/tt]
- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top