Status returned from SQL command

4 posts, 1 answers
  1. Nigel
    Nigel avatar
    53 posts
    Member since:
    Jan 2012

    Posted 18 Jun 2012 Link to this post

    Hi,

    Is it possible to capture the value returned from executing a SQL statement executed through the Code Behind window?
    I have a script that works fine, and the VB in the code behind window also works fine.  However, I want to expand the VB script if possible, so that I can execute the following algorithm:

    Open connection to database
    Execute SQL statement to check if value exists in a database table
    If the value exists then
        Do this
    Otherwise
        Do this
    End If
    Close connection to database

    What I need to understand is how to get a result back from an execution statement such as:
       
         thisCommand.CommandText = "SELECT myValue FROM DatabaseTable"
         thisCommand.ExecuteNonQuery()

    Is this possible?  Is there a better way?  If so, what do I need to do to make it happen?

    When I run the following code, the value returned to my variable aResult is always -1, regardless of whether the search succeeds or not:

    SQL_Command = "SELECT * FROM LookupItemsTexts WHERE [Text] = 'fred'"
    Log.WriteLine(SQL_Command)  'debug line
    'Now execute the command
    thisConnection.Close()    
    thisConnection.Open()
    thisCommand.CommandText = SQL_Command
    aResult = thisCommand.ExecuteNonQuery()
    Log.WriteLine(aResult.ToString())  'debug line

    Thanks,
    Nigel Edwards.

  2. Answer
    Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 18 Jun 2012 Link to this post

    Hello Nigel,

    Unfortunately we won't be able to troubleshoot this for you, as this code is not specific to Test Studio. The best we can provide is this basic article to get you started, which you may have already seen.

    Kind regards,
    Anthony
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Nigel
    Nigel avatar
    53 posts
    Member since:
    Jan 2012

    Posted 19 Jun 2012 Link to this post

    Okay, thanks Anthony.

    Has ANYONE in the community any experience of running SQL from the code behind window (VB or C)?  I must assume that the Telerik libraries don't have any function that picks up and returns a value from SQL for an executed query.

    If not then this might be something that the Telerik team should consider implementing in a future Test Studio release.  After all, SQL is (I think) the most widely used DB language in use today.
  4. Nigel
    Nigel avatar
    53 posts
    Member since:
    Jan 2012

    Posted 21 Jun 2012 Link to this post

    I believe I have found the answer i wanted in a Telerik on-line documentation page:

    http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/code-samples/general/access-sql-database.aspx

    The code on that page shows me how to check for the existence of a data item in the database:
    Log.WriteLine("Value of City column: " + DirectCast(thisReader("City"), [String]))
    Although I can't explicitely use code such as 
        aResult = thisCommand.ExecuteNonQuery()
    to verify that a command has executed correctly, I can use a form of the first snippet to capture a value and prove that the command has executed by checking the database to see if a value still exists (or doesn't) after the command has been executed.

    Thanks,Nigel.
Back to Top