PDA

View Full Version : Setting CursorType and LockType with Open Method


donmateo
10-28-2008, 08:17 PM
Hey Guys,

I am trying to set the CursorType and LockType of the recordset object in the below code. I am using the Open method to set both properties. After I call the method the properties are being reset. Any ideas?

Source:


cmd.ActiveConnection = getConn()
cmd.CommandType = adcmdStoredProc
cmd.CommandText = "spDemoGetQuestions"

cmd.Parameters.Append cmd.CreateParameter("demogroup",adInteger,adParamInput,,DemoGroup)

rs.Open cmd,,adOpenKeyset,adLockOptimistic

response.Write("ct: " & rs.CursorType & "<br />")
response.Write("lt: " & rs.LockType & "<br />")
response.Write("rc: " & rs.RecordCount & "<br />")


Output:

ct: 0
lt: 1
rc: -1

Thanks

Brandoe85
10-28-2008, 08:34 PM
How are you creating your connection object? It could be that you are using a provider that does not support those properties.

Good luck;

brazenskies
10-28-2008, 10:35 PM
recordcount is showing as -1 because it's probably still using the default, forward-only cursor.

Also to use the recordcount function you have to explicitly set rs as ADODB.RECORDSET (i think, don't quote me on that tho!)

Try using this...


...
rs.cursorlocation = 3
rs.Open cmd, theCon,1,2
...

ess
10-29-2008, 04:34 PM
You need to sepcify the cursor type

for example

rs.CursorType = 3
rs.CursorLocation = 3

You can then find out the number of records retrieve

Response.Write "Total records: " & rs.RecordCount