Forum Discussion

Ryu's avatar
Ryu
Contributor
6 years ago
Solved

Way to check column with ADODriver?

I have ADODriver executing a SQL query that returns a small 3x2 table, and the value that I am needing is in the second column.  Now, it isn't it's own column in the database, but rather a count of all of the matching entries in the database.  I know I can use ADODriver to look at different rows, but what about different columns?  I tried .Value[row][column] and it instead gave me the second character in the string in the first cell in the row (whereas .Value[row] returns the full value).  Can I get it to see the second column, or will I need to rewrite the query to just return one column?  Thanks!

  • The parameter of "Value" indicates the column in the current row.  The ADODriver returns a collection of rows you iterate through and then you specify which column you want to work with using Value(<column indicator>).

     

    So, you'll iterate through the rows using a while loop and then, each time through the loop, you reference Value(1).  That will return the value of the 2nd column (column index is based on zero).

     

    See https://support.smartbear.com/testcomplete/docs/reference/program-objects/ddtdriver/value.html

5 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    The parameter of "Value" indicates the column in the current row.  The ADODriver returns a collection of rows you iterate through and then you specify which column you want to work with using Value(<column indicator>).

     

    So, you'll iterate through the rows using a while loop and then, each time through the loop, you reference Value(1).  That will return the value of the 2nd column (column index is based on zero).

     

    See https://support.smartbear.com/testcomplete/docs/reference/program-objects/ddtdriver/value.html

    • Ryu's avatar
      Ryu
      Contributor

      Ah, I guess I got confused because the function we have that reads the DB has "row" passed as a parameter.  I suppose they meant "col" and just misnamed it.  I see, thanks!

    • Ryu's avatar
      Ryu
      Contributor

      tristaanogre, sorry to ask, but can you give me an example of how to loop through the rows?  I can't seem to find one in the support docs, and what I am trying is not working (telling me the object I am trying to index is not indexable).  I'll keep trying different things in the meantime.

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Sure...  Now, this is just kind of psedo code, but this should be what you're looking for

         

        var driverObject = DDT.ADODriver(<connection string>, <table name>);
        driverObject.ADOCommandObject.CommandText = <SQL Query> //This is optional.... you mentioned you're doing a custom query
        while (!driverObject.EOF){
            Log.Message('Value of 2nd column is' + driverObject.Value(1));
            driverObject.Next();
        }

        There's sample code for doing an Excel driver showing the while loop... but the concept is the same... 


        https://support.smartbear.com/testcomplete/docs/reference/program-objects/ddtdriver/next.html