SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Singapore
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Needed help in Recordcount

    Hello,

    Sorry to trouble u guy again, i tried using a few method from the forum and fail. So anyone can help me out with this, i wanted to count the total number of record in the on of the table Namecard, so tried this code but fail, anyone can help me out?

    <%
    Dim rsCount
    Dim MyConn
    Set MyConn = Server.CreateObject("ADODB.Connection")
    MdbFilePath = Server.MapPath("Admin.mdb")
    MyConn.Open "UID=User;PWD=111111;Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"
    Set RS = Server.CreateObject("ADODB.Recordset")
    Set rsCount = Server.CreateObject("ADODB.Recordset")
    %>


    <tr>
    <td height="18" colspan="10" bgcolor="#CECFCE"><span class="style15">You have
    <%
    Set rsCount = MyConn.Open
    rsCount.MoveLast : rsCount.MoveFirst
    intCount = rsCount.RecordCount
    Response.Write(intCount)
    %>
    of contacts</span></td>

    Do anyone know where went wrong?

  2. #2
    SitePoint Enthusiast Nawaz Ijaz's Avatar
    Join Date
    Feb 2005
    Location
    Lahore, Pakistan
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    creating two recordset objects -- > why ?

    Set RS = Server.CreateObject("ADODB.Recordset")
    Set rsCount = Server.CreateObject("ADODB.Recordset")

    if U want to count the nos of rows returned by the recordset object, do following

    Step-1: Create DB Object

    Dim MyConn
    Set MyConn = Server.CreateObject("ADODB.Connection")
    MdbFilePath = Server.MapPath("Admin.mdb")
    MyConn.Open "UID=User;PWD=111111;Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"

    Step-2: Create Recordset object that will be used to store the result returned against ur query from ur DB.

    set rs = server.CreateObject("ADODB.Recordset")
    Step 3: Ur_Query like "select * from tablename"


    Step-4: then open recordset like this, if you didn't give 3,3 at the end. It will open it and then take the cursor rite at the top and if u try to display the count of recordset it will give you -1, i.e; (bcoz your cursor is just above the first row.)

    rs.open Ur_Query, Ur_DB_Object,3,3
    Step-5: Show total nos of records returned against ur query.

    response.write (rs.recordcount)
    Sure this will help.
    Nawaz Ijaz [Lahore, Pakistan]
    Boy: He is big..i wont like to fight him...
    Achilles: Thatz Y no one wud remember u after thousand years...!!

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Singapore
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wat is Ur_DB_Object??

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Singapore
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <%
    sql="SELECT * FROM NAMECARD"
    rsCount.Open MyConn, Ur_DB_Object, 3 , 3---->Line 431
    Response.Write(rsCount)%>

    It gave me the same error msg
    ADODB.Recordset error '800a0bb9'

    Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

    /i-Metz/iMetzContacts.asp, line 431


    The

  5. #5
    SitePoint Enthusiast Nawaz Ijaz's Avatar
    Join Date
    Feb 2005
    Location
    Lahore, Pakistan
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "rsCount" in your code is the recordset object. you can't display this with response.write (rsCount)
    it sohuld be like this;

    response.write (rsCount.recordcount)
    try this code ;

    <%
    sql="SELECT * FROM NAMECARD"
    rsCount.Open sql, MyConn, 3 , 3
    Response.Write(rsCount.recordcount)
    %>
    Nawaz Ijaz [Lahore, Pakistan]
    Boy: He is big..i wont like to fight him...
    Achilles: Thatz Y no one wud remember u after thousand years...!!

  6. #6
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,294
    Mentioned
    123 Post(s)
    Tagged
    1 Thread(s)
    You'll cause more stress on the server just doing a blatant select all and getting the record count. The following code would be more efficient (change KeyID, TableName, and the condition to be searched for):


    Code:
    <%
    Dim rsCount, myConn, rs, strSQL
    Set myConn = Server.CreateObject("ADODB.Connection")
    myConn.Open "UID=User;PWD=111111;Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Admin.mdb") & ";"
    Set rs = Server.CreateObject("ADODB.Recordset")
    strSQL = "SELECT Count(KeyID) AS MyCount from TableName WHERE Cond1 = 'Q'"
    rs.Open strSQL, myConn
    rsCount = rs("MyCount")
    %>
    <tr>
     <td height="18" colspan="10" bgcolor="#CECFCE">
      <span class="style15">You have <% =rsCount %> contact<% if rsCount <> 1 then %>s<%end if%></span>
     </td>
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  7. #7
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Singapore
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    I got another problem with the Rcordcount: I can do recordcount for the first record in the table but the after that it will gave me an error for the subsequent recordcount:

    <table width="720" border="1" cellpadding="0" cellspacing="0">
    <tr bordercolor="#6699FF" bgcolor="#0066FF">
    <td width="44"><div align="center"></div></td>
    <td width="340"><div align="center" class="style7">
    <div align="center">Forum</div>
    </div></td>
    <td width="70"><div align="center" class="style6 style8">
    <div align="center">Topics</div>
    </div></td>
    <td width="256"><div align="center"><span class="style6"><span class="style6"><span class="style8">Last Post </span></span></span></div></td>
    </tr>
    <tr bordercolor="#6699FF" bgcolor="#FFFFFF">
    <td colspan="4"><span class="style9">i-Metz Application discussion </span></td>
    </tr>
    <tr bordercolor="#6699FF" bgcolor="#FFFFFF">
    <td>&nbsp;</td>
    <td width="340" height="0"><p class="style10"><A HREF="ViewMessage.asp?<%= Server.HTMLEncode(MM_keepForm) & MM_joinChar(MM_keepForm) & "ForumMainID=" & "1" %>">i-Metz Application Help</A></p>
    <p class="style11">Post any comment of our website and ways to improve </p></td>
    <td><div align="center">
    <%
    ID = 1
    sql="SELECT * FROM FORUM where ForumMainID = '"&ID&"';"
    rsCount.Open sql, MyConn, 3 , 3--->Line 257
    Response.Write(rsCount.RecordCount)
    rsCount.close()
    set rsCount = nothing
    MyConn.close()
    set MyConn = nothing%>
    </div></td>
    <td>&nbsp;</td>
    </tr>
    <tr bordercolor="#6699FF" bgcolor="#FFFFFF">
    <td height="0" colspan="4"><span class="style9">IT discussion</span></td>
    </tr>
    <tr bordercolor="#6699FF" bgcolor="#FFFFFF">
    <td>&nbsp;</td>
    <td height="0" class="style10"><A HREF="ViewMessage.asp?<%= Server.HTMLEncode(MM_keepForm) & MM_joinChar(MM_keepForm) & "ForumMainID=" & "2" %>">ASP</A></td>
    <td><div align="center">
    <%
    ID = 2
    sql="SELECT * FROM FORUM where ForumMainID = '"&ID2&"';"
    rsCount.Open sql, MyConn, 3 , 3
    Response.Write(rsCount.RecordCount)
    rsCount.close()
    set rsCount = nothing
    MyConn.close()
    set MyConn = nothing%>
    </div></td>
    <td>&nbsp;</td>
    </tr>
    <tr bordercolor="#6699FF" bgcolor="#FFFFFF">
    <td>&nbsp;</td>
    <td height="0" class="style10"><A HREF="ViewMessage.asp?<%= Server.HTMLEncode(MM_keepForm) & MM_joinChar(MM_keepForm) & "ForumMainID=" & "3" %>">PHP</A></td>
    <td><div align="center">
    <%
    ID = 3
    sql="SELECT * FROM FORUM where ForumMainID = '"&ID&"';"
    rsCount.Open sql, MyConn, 3 , 3
    Response.Write(rsCount.RecordCount)
    rsCount.close()
    set rsCount = nothing
    MyConn.close()
    set MyConn = nothing%>
    </div></td>
    <td>&nbsp;</td>
    </tr>
    </table>

    The error is:
    Microsoft VBScript runtime error '800a01a8'

    Object required

    /i-Metz/iMetzForum.asp, line 257


    What shd i do?

  8. #8
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i would advice to best trace your errors, you highlight line 257 to make it easy to debug. Your code isnt complete

  9. #9
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,294
    Mentioned
    123 Post(s)
    Tagged
    1 Thread(s)
    It's probably these two lines at the previous count:

    MyConn.close()
    set MyConn = nothing

    take them out and it should be fine.
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  10. #10
    SitePoint Enthusiast Nawaz Ijaz's Avatar
    Join Date
    Feb 2005
    Location
    Lahore, Pakistan
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is hte problem, either take these lines at the end of your code as our advisor already said.

    rsCount.close()
    set rsCount = nothing
    MyConn.close()

    Or right after these lines open your connection again like this.

    MyConn.Open "UID=User;PWD=111111;Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"
    Nawaz Ijaz [Lahore, Pakistan]
    Boy: He is big..i wont like to fight him...
    Achilles: Thatz Y no one wud remember u after thousand years...!!

  11. #11
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Singapore
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry to trouble you again an error popup again this i dont understand, it previously was working ok but now it can't work anymore even my first recordcount wouldn't work, what has happen?

    <table width="720" border="1" cellpadding="0" cellspacing="0">
    <tr bordercolor="#6699FF" bgcolor="#0066FF">
    <td width="44"><div align="center"></div></td>
    <td width="340"><div align="center" class="style7">
    <div align="center">Forum</div>
    </div></td>
    <td width="70"><div align="center" class="style6 style8">
    <div align="center">Topics</div>
    </div></td>
    <td width="256"><div align="center"><span class="style6"><span class="style6"><span class="style8">Last Post </span></span></span></div></td>
    </tr>
    <tr bordercolor="#6699FF" bgcolor="#FFFFFF">
    <td colspan="4"><span class="style9">i-Metz Application discussion </span></td>
    </tr>
    <tr bordercolor="#6699FF" bgcolor="#FFFFFF">
    <td>&nbsp;</td>
    <td width="340" height="0"><p class="style10"><A HREF="ViewMessage.asp?<%= Server.HTMLEncode(MM_keepForm) & MM_joinChar(MM_keepForm) & "ForumMainID=" & "1" %>">i-Metz Application Help</A></p>
    <p class="style11">Post any comment of our website and ways to improve </p></td>
    <td><div align="center">
    <%
    ID = 1
    sql="SELECT * FROM FORUM where ForumMainID = '"&ID&"';"
    rsCount.Open sql, MyConn, 3 , 3--->Line 238
    Response.Write(rsCount.RecordCount)
    rsCount.close()
    set rsCount = nothing
    MyConn.close()
    set MyConn = nothing%>
    </div></td>
    <td>&nbsp;</td>
    </tr>
    <tr bordercolor="#6699FF" bgcolor="#FFFFFF">
    <td height="0" colspan="4"><span class="style9">IT discussion</span></td>
    </tr>
    <tr bordercolor="#6699FF" bgcolor="#FFFFFF">
    <td>&nbsp;</td>
    <td height="0" class="style10"><A HREF="ViewMessage.asp?<%= Server.HTMLEncode(MM_keepForm) & MM_joinChar(MM_keepForm) & "ForumMainID=" & "2" %>">ASP</A></td>
    <td><div align="center">
    <%
    ID = 2
    sql="SELECT * FROM FORUM where ForumMainID = '"&ID2&"';"
    rsCount.Open sql, MyConn, 3 , 3
    Response.Write(rsCount.RecordCount)
    rsCount.close()
    set rsCount = nothing
    MyConn.close()
    set MyConn = nothing%>
    </div></td>
    <td>&nbsp;</td>
    </tr>
    <tr bordercolor="#6699FF" bgcolor="#FFFFFF">
    <td>&nbsp;</td>
    <td height="0" class="style10"><A HREF="ViewMessage.asp?<%= Server.HTMLEncode(MM_keepForm) & MM_joinChar(MM_keepForm) & "ForumMainID=" & "3" %>">PHP</A></td>
    <td><div align="center">
    <%
    ID = 3
    sql="SELECT * FROM FORUM where ForumMainID = '"&ID&"';"
    rsCount.Open sql, MyConn, 3 , 3
    Response.Write(rsCount.RecordCount)
    rsCount.close()
    set rsCount = nothing
    MyConn.close()
    set MyConn = nothing%>
    </div></td>
    <td>&nbsp;</td>
    </tr>
    </table>

    Microsoft OLE DB Provider for ODBC Drivers error '80040e07'

    [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

    /i-Metz/iMetzForum.asp, line 238


Bookmarks

Posting Permissions

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