Forum Discussion

jasmeenkaur27's avatar
jasmeenkaur27
Contributor
7 years ago
Solved

Record Count returns -1

Hi,

 

On executing the below code the record count returned is -1 even though the resultset has 100 records.

 

unction getParentEventId()

{

 

// Creates and opens a connection

var Conn = new ActiveXObject("ADODB.Connection");

 

var ConnectionString = "xx"

var Rs = new ActiveXObject("ADODB.Recordset");

Rs.ActiveConnection = Conn;

Rs.Open("query")

Rs.MoveFirst();

var rowcount= Rs.RecordCount

Log.Message("The rowcount is"+rowcount)

 

  • I learned this a while back: Depending upon how an ADO record set is open, it is a "forward only" cursor which means it is initiated at row 1 and you don't get a row count back.  There are other ways of opening a record set that will give you access to the number of rows. 

     

    however, if all you're looking for is to iterate through the records, you can use the EOF property to check for when you've hit the end to break out of a while loop.

1 Reply

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    I learned this a while back: Depending upon how an ADO record set is open, it is a "forward only" cursor which means it is initiated at row 1 and you don't get a row count back.  There are other ways of opening a record set that will give you access to the number of rows. 

     

    however, if all you're looking for is to iterate through the records, you can use the EOF property to check for when you've hit the end to break out of a while loop.