RecordCount problem with static recordset

  • I want to use RecordCount before i run through the recordset. I'm specifying the cursor type and there are three records returned, however RecordCount is always -1! Any ideas?

    conn = Server.CreateObject("ADODB.Connection")

    conn.Open(Application("JobDB"));

    cmd = Server.CreateObject("ADODB.Command")

    cmd.ActiveConnection = conn;

    cmd.CommandType = adCmdStoredProc;

    cmd.CommandText = "GetDataRequest";

    cmd.Parameters.Append (cmd.CreateParameter("userID", adVarChar, adParamInput, 64));

    cmd.Parameters("userID") = Application("userID");

    rs = Server.CreateObject("ADODB.Recordset");

    rs.CursorType = 3;

    rs.Open(cmd);

  • Hi!

    There is a problem to use .RecordCount if the recordset does not contain all columns of a table, and don't ask me why it is like that

    To solve this you could run thru all records with .MoveNext and store the number of records in a temporary variable and then use .MoveFirst to get back to the first record of the recordset.


    robbac
    ___the truth is out there___

  • Try changing the ADODB cursorlocation to be adUseClient.  Then you should be able to get a recordcount.  The problem is the recordcount uses client always and when the cursor location is on the server it can't get a count.

    If the above gives a -1 add re.movelast and rs.movefirst and then check record count.

     



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • Simply do a .movelast , .movefirst and then do the .recordcount worked for me. for extra security you can also put a order by in your query (even if you dont need it). Dont ask me why either ..... it just works.

    PhilTheThrill


    Never argue with a fool.
    First ill bring you down to his level, then, ill beat you with experience.
    Phil.

  • To get a RecordCount, you must use a Client side cursor location (adUseClient), and a static cursor type (adOpenStatic). ADO then gets all the records back from the server so you can check RecordCount

    connection.CursorLocation=adUseClient

    connection.CursorType = adOpenStatic

     


    Julian Kuiters
    juliankuiters.id.au

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply