Results 1 to 6 of 6

Thread: ASP VBScript ADO Recordset RecordCount

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140

    ASP VBScript ADO Recordset RecordCount

    Given this code...

    Code:
    <% @Language="VBScript" %>
    <%
      Option Explicit
    
    %>
    <!---#include virtual="/Gabby/Utilities.inc"-->
    <!---#include virtual="/Gabby/Globals.inc"-->
    <%
    
      Dim adodbConn, adodbRS
      Dim strSQL
    
      Set adodbConn = Server.CreateObject("ADODB.Connection")
      Set adodbRS = Server.CreateObject("ADODB.Recordset")
    
      adodbConn.Open MonitorCS, MonitorUserID, MonitorPassword
    
      strSQL = "SELECT Node FROM Node"
      adodbRS.Open strSQL, adodbConn, adOpenForwardOnly, adLockReadOnly
    %>
    <html>
      <head>
        <title>Test Page</title>
      </head>
      <body>
        <p><%=adodbRS.RecordCount%></p>
        <%While Not adodbRS.EOF%>
          <p><%=adodbRS.Fields("Node").Value%></p>
          <%adodbRS.MoveNext%>
        <%Wend%>
      </body>
    </html>
    I get this result...

    Code:
    -1
    
    CICS-Region-1
    
    CICS-Region-2
    
    CICS-Region-3
    
    localhost
    
    NT-BackOffice-Server
    
    Unix-DB-Server
    
    Unix-DB-Server
    
    Unix-DB-Server
    
    UnixGateway
    
    UnixGateway2
    Since ADODBRecordset.RecordCount obviously doesn't work, is there any other way?
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  2. #2
    joan_fl
    Guest
    try this sql statement:

    SELECT COUNT(Node) as NodeCount, Node FROM Node ORDER BY Node

    You will now have a column NodeCount that contains the node count.

    Hope this helps,

    Joan

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    I always forget aliasing in SQL statements. I actually like that solution, though. A slap in the face to VBScript.

    Though, I'm having problems.

    Code:
      strSQL = "SELECT Node, COUNT(Node) as NodeCount FROM Node"
      'or
      strSQL = "SELECT COUNT(Node) as NodeCount, Node FROM Node"
    Both give me an error.

    [Microsoft][ODBC Microsoft Access Driver] You tried to execute a query that does not include the specified expression 'Node' as part of an aggregate function.
    If I drop "Node" and just ask for "COUNT(Node) as NodeCount" it works, though I just get the count and not the data.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  4. #4
    Hyperactive Member billwagnon's Avatar
    Join Date
    Jul 1999
    Location
    St. Louis, Missouri, Mississippi Valley
    Posts
    290
    yourRS.recordcount should work if you substitute

    'adOpenKeyset' for 'adOpenForwardOnly'

  5. #5
    joan_fl
    Guest
    Sorry, instead of the ORDER BY. Use GROUP BY...

    SELECT COUNT(Node) as NodeCount, Node FROM Node GROUP BY Node

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    There we go, thank you both.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

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