Results 1 to 7 of 7

Thread: Record Count question (yes it's a Keyset Cursor)

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2001
    Posts
    33

    Question Record Count question (yes it's a Keyset Cursor)

    I'm just doing a basic little test to print out records and a record count, and even though I've set the cursor to adOpenKeyset (both with the CursorType=adOpenKeyset and w/i the objRS.Open properties) and it's still giving me the blasted -1 !!
    I've also set the cursor location to client, and done some manipulations there as well.

    Here's the code, any thoughts? Much appreciated!

    <%
    Dim objConn
    Set objConn = CreateObject("ADODB.Connection")
    objConn.ConnectionString="DSN=A_Test"
    objConn.Open

    Dim objRS, strSQL
    Set objRS=Server.CreateObject("ADODB.Recordset")
    strSQL="SELECT * FROM Products"

    objRS.Open strSQL, objConn, adOpenKeyset

    Response.Write "<B> A Listing of our Products </B><BR>"
    Response.Write "Record Count: " & objRS.RecordCount & "<BR>"

    Do While Not objRS.EOF
    Response.Write objRS("Brand") & " " & objRS("Model") & "<BR>"
    objRS.MoveNext
    Loop

    objRS.Close
    Set objRS = Nothing
    objConn.Close
    Set objConn = Nothing

  2. #2
    Lively Member
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    115
    Try do it like this instead:

    Code:
    <% 
    Dim objConn 
    Set objConn = CreateObject("ADODB.Connection") 
    objConn.ConnectionString="DSN=A_Test" 
    objConn.Open 
    
    strSQL="SELECT * FROM Products" 
    strSQL2 = "SELECT Count(*) as ProdCount FROM Products"
    
    set objRs = objConn.Execute(strSQL)
    set objRs2 = objConn.Execute(strSQL2)
    
    Response.Write "<B> A Listing of our Products </B><BR>" 
    Response.Write "Record Count: " & objRS2("ProdCount") & "<BR>" 
    
    Do While Not objRS.EOF 
        Response.Write objRS("Brand") & " " & objRS("Model") & "<BR>" 
        objRS.MoveNext 
    Loop 
    
    objRS.Close 
    Set objRS = Nothing 
    objRs2.Close
    Set objRs2 = Nothing
    objConn.Close 
    Set objConn = Nothing
    %>
    I haven't tested this code now, but it should be working. Let me know if it doesn't...

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2001
    Posts
    33

    Smile Yes, that definitely does work -

    but I wonder why the recordcount property does not, even though I think I've got all the cursor settings correct.....

    It's just the principle of knowing why :-)

    In the meantime though, I will use your code so I can keep going with my happy little code!

    Thanks very much!!

  4. #4
    Hyperactive Member
    Join Date
    Apr 2000
    Location
    Sudbury, Ontario, Canada
    Posts
    274
    If you want to use the RecordCount property you can also use adOpenStatic.

    Another option (if you're interested) with a forwardonly recordset, would be as follows:
    Code:
    Dim objConn 
    Set objConn = CreateObject("ADODB.Connection") 
    objConn.ConnectionString="DSN=A_Test" 
    objConn.Open 
    
    Dim objRS, strSQL 
    
    Dim I, strList
    
    Set objRS=Server.CreateObject("ADODB.Recordset") 
    strSQL="SELECT * FROM Products" 
    
    objRS.Open strSQL, objConn, adOpenForwardOnly 
    
    I = 1
    Do While Not objRS.EOF 
      strList = strList & objRS("Brand") & " " & objRS("Model") & "<BR>" 
      objRS.MoveNext
      I = I + 1
    Loop 
    
    Response.Write "<B> A Listing of our Products </B><BR>" 
    Response.Write "Record Count: " & I & "<BR>" 
    Response.Write strList
    
    objRS.Close 
    Set objRS = Nothing 
    objConn.Close 
    Set objConn = Nothing

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2001
    Posts
    33
    I've tried w/ the cursor set to adOpenStatic, and get the same -1... It makes me wonder if it's something in my connection string or the provider settings that doesn't recognize that property.

    The looping works as well, though, so at least I have options!!

    Thanks for the help!

  6. #6
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    1) Use Server.CreateObject with ASP

    2) Specify a client side cursor.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  7. #7

    Thread Starter
    Member
    Join Date
    Jun 2001
    Posts
    33

    Cool

    That worked!! I thought I'd specified client-side cursor before, but I guess it was "user error"

    Thanks very much for your help, this one was stupid and it was bugging me!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width