Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    recordset counter

    i tried to count the number of records in my query,
    i used loop and rs.recordcount, each one give me different result
    and rs.recordcount always equal -1

    this my code:
    <%
    email=Trim(Request.Form("frmail"))

    set con=server.CreateObject("adodb.connection")
    con.open("shazly")
    set rs = Server.CreateObject("ADODB.recordset")
    sql2="select email from members where email='"&email&"'"
    rs.Open sql2, con

    counts=rs.RecordCount

    s=0
    while not rs.eof
    s=s+1
    rs.movenext
    wend

    Response.Write("s="&s)
    Response.Write("<br>")
    response.Write("count="&counts)
    Response.Write("<br>")

    %>
    the result:
    s=60
    count=-1
    ?

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Might be a problem with the cursor you are using.

    Try refering here: http://www.asp101.com/samples/db_count.asp

    And like its mentioned on the afore mentioned page, you also can get the count by using the following SQL query:
    SELECT COUNT(field_name) FROM table_name;
    OracleGuy

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    oracleguy is correct.
    but you can also try this if this works, ive seen this trick somewhere.

    rs.Open sql2, con
    rs.movelast
    counts=rs.RecordCount
    response.write counts
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok it works with sql query,but with glenngv's code it give me this error:
    Error Type:
    Microsoft OLE DB Provider for ODBC Drivers (0x80040E24)
    Rowset does not support fetching backward.
    at this line: rs.movelast

    i dont know why?

  • #5
    Regular Coder
    Join Date
    Nov 2002
    Location
    Loughborough (UK)
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Any help?

    Not sure if I'm missing your point, but I use this to count my records, you can specify a criteria in the WHERE statement too...

    <%
    SQLnumof = "SELECT count(*) AS numof FROM #table#
    Set objRS = oConnection.Execute(SQLnumof)
    numof = objRS("numof")
    response.write numof
    %>

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts
    to christrinder:
    i mean this method give me error but when using sql query(like yours) it works
    <%
    set con=server.CreateObject("adodb.connection")
    con.open("shazly")
    set rs = Server.CreateObject("ADODB.recordset")
    sql2="select email from members where email='"&email&"'"
    rs.Open sql2, con
    rs.movelast
    counts=rs.RecordCount
    response.write counts
    %>

    Error Type:
    Microsoft OLE DB Provider for ODBC Drivers (0x80040E24)
    Rowset does not support fetching backward.
    at this line: rs.movelast


  •  

    Posting Permissions

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