Forum Discussion

rapple_yea's avatar
10 years ago

Using '@@ROWCOUNT' SQL query in TestComplete

Hello,



We are trying to create a test in which we utilize several sql queries and Update statements.  As part of that process, upon executing an update statement we want to get the rowcount of rows affected for validation purposes.



The following query string works perfectly well in sql server management studio:


Update (table) set (column) = 1 where name = 'frmCodeImport' and security_role_id = 2 SELECT @@ROWCOUNT



When executing this string in TestComplete, like so: 

Cmd["CommandText"] = dbquery;

RecSet = Cmd["Execute"]();



RecSet is returned as a blank object.  There are no values contained in it, even though it should be returning the value given by @@rowcount.  We have tried casting, using aliases, running the command alone, etc, all to no avail.



Is there some special way to execute the "select @@rowcount" command?  Or something else that I can try, or have missed?

2 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi Sean,

     

    ADOCommand.Execute returns the number of affected records through the RecordsAffected parameter, not through the return value. Here's a quote from the documentation:


    Set recordset = command.Execute(RecordsAffected, Parameters, Options)

    RecordsAffected

    Optional. A Long variable to which the provider returns the number of records that the operation affected. The RecordsAffected parameter applies only for action queries or store procedures.


    The only thing is, RecordsAffected is an out parameter and C#Script doesn't support out parameters natively. You can try the OutParameterWrapper extension as a workaround. Something along the lines of (I didn't test this though):

    var params = ConvertJScriptArray([0]);
    var result = OutParameterWrapper.CallObjectMethod(Cmd, "Execute", params).toArray();
    Log.Message(result[0]);

    Hope this helps!