RS.RecordCount always returns -1

Discussion in 'ASP General' started by jl, Aug 4, 2005.

  1. jl

    jl Guest

    Hello,
    I am trying to determine if a recordset is empty or not, and if
    it is empty print out a message saying no records found. I thought
    I could use rs.RecordCount but it always seems to return -1 no
    matter if there are records in the rs or not. Does anyone have
    any ideas as to why this doesn't work and how to get it to work.
    Thanks in advance. The code is below.
    Joe

    Const adOpenStatic = 3
    Const adLockReadOnly = 1
    Dim frmFileType, frmCategory, frmEvent, frmUser, objConn2, objRS5
    Dim tmpsql5, strSQL5
    frmFileType = request.form("fileType")
    frmCategory = request.form("category")
    frmEvent = request.form("theevent")
    frmUser = request.form("theUser")
    if frmUser = "ALL" then
    userPart = ""
    Else
    userPart = "And user_id = " & frmUser
    End if
    tmpsql5 = "Select * from table where type_id = " & frmFileType & " AND
    category_id = " & frmCategory & " AND event_id = " & frmEvent &
    userPart
    strSQL5 = tmpsql5
    Set objConn2=Server.CreateObject("ADODB.Connection")
    Set objRS5=Server.CreateObject("ADODB.Recordset")
    objConn2.Open strConnect
    objRS5.Open strSQL5, objConn2, adOpenStatic, adLockReadOnly
    i=objRS5.RecordCount
    response.write("The number of records is: " & i)
    jl, Aug 4, 2005
    #1
    1. Advertising

  2. jl

    Curt_C [MVP] Guest

    jl wrote:
    > Hello,
    > I am trying to determine if a recordset is empty or not, and if
    > it is empty print out a message saying no records found. I thought
    > I could use rs.RecordCount but it always seems to return -1 no
    > matter if there are records in the rs or not. Does anyone have
    > any ideas as to why this doesn't work and how to get it to work.
    > Thanks in advance. The code is below.
    > Joe



    Perhaps...
    http://www.aspfaq.com/show.asp?id=2193

    --
    Curt Christianson
    site: http://www.darkfalz.com
    blog: http://blog.darkfalz.com
    Curt_C [MVP], Aug 4, 2005
    #2
    1. Advertising

  3. > I am trying to determine if a recordset is empty or not, and if
    > it is empty print out a message saying no records found. I thought
    > I could use rs.RecordCount


    Why not use the EOF property?

    set rs = conn.execute(sql)
    if rs.eof then
    Response.Write "no results"
    else
    ...
    end if
    Aaron Bertrand [SQL Server MVP], Aug 5, 2005
    #3
  4. jl

    jl Guest

    Hello,
    EOF is what I ended up using.
    Thanks for all of your suggestions.
    Joe
    jl, Aug 22, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Caliendo

    RecordCount of a datareader

    Steve Caliendo, Jun 2, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,406
    John Oakes
    Jun 2, 2004
  2. Daan
    Replies:
    4
    Views:
    15,573
    chris22smith
    Mar 18, 2009
  3. Replies:
    2
    Views:
    2,854
    Peter Rilling
    Oct 13, 2005
  4. =?Utf-8?B?UGF1bA==?=

    DataReader and RecordCount

    =?Utf-8?B?UGF1bA==?=, Oct 21, 2005, in forum: ASP .Net
    Replies:
    9
    Views:
    37,805
    Patrick.O.Ige
    Oct 22, 2005
  5. Serge Myrand

    ADODB.RecordSet, RecordCount always return -1

    Serge Myrand, Jun 23, 2004, in forum: ASP General
    Replies:
    7
    Views:
    290
    Bob Barrows [MVP]
    Jun 30, 2004
Loading...

Share This Page