IF statements and RecorDcount in ASP

IF statements and RecorDcount in ASP

Post by Tim Patto » Fri, 09 Mar 2001 04:47:57

I'm using an IF statement in a stored procedure to choose between two
SELECTs like this

IF (some condition)

I return the recordset to my ASP pages like this:

  var cmd = Server.CreateObject ( "Adodb.command" );
  cmd.ActiveConnection = "DSN="+DealDatabase.DSN2+";";

adParamInput, 0));

adParamInput, 0));

  var rs=Server.CreateObject ( "Adodb.Recordset" );
  rs.CursorType = adOpenStatic;
  rs.LockType = adLockOptimistic;

And rs.RecordCount is always is -1.  If I modify the SP to get rid of the IF
clause and just have one SELECT, it works fine.  It seems I always have to
jump through hoops to get RecordCounts and paging recordset with ADO.
Anyone have any advice?



1. ASP Recordset Recordcount = -1 ?????

First time for ASP.

Seems like this should work?

But recordCount returns -1?

Please help,




<% Language=vbScript %>
    Dim strProvider
    strProvider = "Driver=Microsoft Access Driver (*.mdb);

    'Open the database connection
    Set cn = Server.CreateObject("ADODB.Connection")
    cn.ConnectionString = strProvider

    ' Build the sql string
    Dim databaseName
    databaseName = "Customers"
    Dim sql
    sql = "SELECT * FROM " & databaseName

    'Create the recordset
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open sql, strProvider

    ' Output teh explorer
    Response.Write("<p align=""center"">" & sql & "</p>")
    Response.Write("<p align=""center"">" & rs.RecordCount & "</p>")

    'Clear up
    Set rs = nothing
    Set cn = nothing


2. Porting from VB4

3. ASP, RecordCount property and sprocs

4. LIKE Operator & Full Text Indexing

5. Can not RecordCount and AddNew from ASP (ODBC)

6. Picture Control

7. how to get a recordcount using ASP and Oracle

8. storing and emailing database data

9. RecordCount returns -1 when inside IF statement

10. DAO Recordcount vs. ADO Recordcount

11. Timeout in simple select statement in ASP after upgrading to SQL2000 from SQL 7

12. need help w/SQL ASP Statement with totals...

13. no select statement output in svrmgr30 or on ASP page but in T.O.A.D it works