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

ASP VBScript class

Status
Not open for further replies.

fid

Programmer
May 10, 2001
20
US
I am writing a Class in ASP
I am trying to pass a database connection object into the class to use within the class

EX: The page:
-------------
set MyConn = Server.CreateObject("ADODB.Connection")
MyConn.Open {My Connection String}

set MyObj = New MyObject
MyObj.Connection = MyConn

response.write MyObj.DoSomething(string)

----------
the class:
----------
Class MyObject

private objConn
public property let Connection(ByRef vData)
objConn = vData
end property

function DoSomething(MyData)
sql = "select * from table where something = " & MyData
set rs=objConn.Execute(sql)
DoSomething=rs("Field")
end function

end class
----------
this results in a Object Expected error
objConn is not empty cause with a test it returns
"Provider=MSSQLSERVER;SERVER=etc...."

if i do this, how ever, the code will work:
public property let Connection(ByVal vData)
set objConn = Server.CreateObject("ADODB.Connection")
objConn.open = vData
end property

but it seems to me this would open 2 connections to the database, wasting resources.. whats the proper syntax to pass as object into the class?
public property let Connection(ByRef vData as Object)
produces a syntax error expected ')'

thanx
Fid
 
set MyConn = Server.CreateObject("ADODB.Connection")
MyConn.Open {My Connection String}

set MyObj = New MyObject
Set MyObj.Connection = MyConn

response.write MyObj.DoSomething(string)

----------
the class:
----------
Class MyObject

private objConn
public property Set Connection(ByRef vData)
Set objConn = vData
end property
Compare Code (Text)
Generate Sort in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top