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 .Connectio n")
oConn.Open("dsn=dsnName;ui d=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 .Connectio n")
oConn.Open("dsn=dsnName;ui d=USER;pwd =PASS;")
Set objSQLCommand = CreateObject("ADODB.Comman d")
set objSQLCommand.ActiveConnec tion = oConn
Dim prmSQLBind1
Set prmSQLBind1 = objSQLCommand.CreateParame ter("Bind1 ", adVarChar, adParamInput,50)
strSQLQuery = "select * from users where username = ?"
objSQLCommand.CommandText = strSQLQuery
objSQLCommand.Parameters.A ppend prmSQLBind1
objSQLCommand(0).value = strUserName
Set rsUsers = CreateObject("ADODB.Record set")
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
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
oConn.Open("dsn=dsnName;ui
Set rsUsers = Server.CreateObject("ADODB
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
oConn.Open("dsn=dsnName;ui
Set objSQLCommand = CreateObject("ADODB.Comman
set objSQLCommand.ActiveConnec
Dim prmSQLBind1
Set prmSQLBind1 = objSQLCommand.CreateParame
strSQLQuery = "select * from users where username = ?"
objSQLCommand.CommandText = strSQLQuery
objSQLCommand.Parameters.A
objSQLCommand(0).value = strUserName
Set rsUsers = CreateObject("ADODB.Record
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Angel!