Link to home
Start Free TrialLog in
Avatar of roblinx
roblinx

asked on

Bind variables with recordset object?

Hi Experts...

Our website makes extensive use of ADODB calls to an Oracle database.  I've been asked by our Oracle dba to take a look at some of the more-often used queries on our web site to try to improve efficiency.  One suggestion was through the use of parameterized (bind) queries.  

My understanding is that these types of queries can only be used with adodb.command objects.  My problem is that I typically use the adodb.recordset object to pull back recordsets, because I need to read the RecordCount property, and I can only do this if I can specify the cursorlocation, cursortype, and locktype properties.

Here's a snippet of what I do now:

dim oConn
Set oConn= Server.CreateObject("ADODB.Connection")
oConn.Open("dsn=dsnName;uid=USER;pwd=PASS;")
Set rsUsers = Server.CreateObject("ADODB.Recordset")
rsUsers.ActiveConnection = oConnRelais
rsUsers.Source = "select * from users where username = '" & strUserName "'"
rsUsers.CursorType = 0
rsUsers.CursorLocation = 3
rsUsers.LockType = 2
rsUsers.Open()

I would like to parameterize the query, so that I can use something like:

dim oConn
Set oConn= Server.CreateObject("ADODB.Connection")
oConn.Open("dsn=dsnName;uid=USER;pwd=PASS;")
Set objSQLCommand = CreateObject("ADODB.Command")
set objSQLCommand.ActiveConnection = oConn

Dim prmSQLBind1
Set prmSQLBind1 = objSQLCommand.CreateParameter("Bind1", adVarChar, adParamInput,50)
strSQLQuery = "select * from users where username = ?"
objSQLCommand.CommandText = strSQLQuery
objSQLCommand.Parameters.Append prmSQLBind1
objSQLCommand(0).value = strUserName

Set rsUsers = CreateObject("ADODB.Recordset")
Set rsUsers = objSQLCommand.Execute

But... when I do this, I can't set the cursorlocation, cursortype, and locktype properties.  They get ignored.

Any help?  Do I need to provide more info?

Thanks in advance!

Rob
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of roblinx
roblinx

ASKER

Wow, that was fast!  Even better, it worked.  :-)

Thanks Angel!