1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

ADO recordset couting??

Discussion in 'C#' started by grobar, Apr 16, 2006.

  1. #1
    I have the following, but am getting -1 as the result and can't resolve it...any help would be appreciated.

    
    <%
    if objrecordset.Supports(adApproxPosition)=true then
      i=objrecordset.RecordCount
      response.write("The number of records is: " & i)
    end if
    
    
    %>
    
    Code (markup):
    i was reading a bunch of stuff on cursors being the problem, but can't figure out how to get that workion.\
    SEMrush
     
    grobar, Apr 16, 2006 IP
    SEMrush
  2. jaymcc

    jaymcc Peon

    Messages:
    139
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You need to do a .movelast on your recordset before it will give you an accurate row count.

    I normally do a .movelast, then get the recordcount, then do a .movefirst

    Jay
     
    jaymcc, Apr 18, 2006 IP
  3. grobar

    grobar Well-Known Member

    Messages:
    642
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    140
    #3
    Thanks, I actually went a different method -

    
    objRecordSet.Open strSQL, objt, adOpenstatic
    dim adsensebling
    adsensebling=objrecordset.recordcount
    'response.write adsensebling
    
    Code (markup):
    also added the adovbs include, and this worked just fine for me!
     
    grobar, Apr 18, 2006 IP
  4. DangerMouse

    DangerMouse Peon

    Messages:
    275
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes, it needs to be "adOpenstatic" in order for the count to work...

    If you don't want to include the advbs.inc file you can look up adOpenstatic and substitute the constant number in place of adOpenstatic
     
    DangerMouse, Apr 19, 2006 IP
  5. frankcow

    frankcow Well-Known Member

    Messages:
    4,862
    Likes Received:
    264
    Best Answers:
    0
    Trophy Points:
    180
    #5
    or you can dump the results into an array, and just read the uBound of the array
     
    frankcow, Apr 19, 2006 IP
  6. DangerMouse

    DangerMouse Peon

    Messages:
    275
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    ubound -1 ;)
     
    DangerMouse, Apr 19, 2006 IP
  7. frankcow

    frankcow Well-Known Member

    Messages:
    4,862
    Likes Received:
    264
    Best Answers:
    0
    Trophy Points:
    180
    #7
    actually it would be ubound +1, as arrays are zero-based ;) ;)
     
    frankcow, Apr 19, 2006 IP
  8. DangerMouse

    DangerMouse Peon

    Messages:
    275
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #8
    true enough :p
     
    DangerMouse, Apr 19, 2006 IP