This is a migrated thread and some comments may be shown as answers.

Using Result of SQL Coded Step as a Data Bind Variable

4 Answers 155 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Korey
Top achievements
Rank 1
Korey asked on 22 Dec 2016, 07:58 PM

I've performed a lot of searching/reading, and cannot find a solution to my problem.  First off, I'm far from a coding expert.  I currently have a custom coded step to connect to SQL Server, run a Query (select/join/etc.), and print the result to the log.  This works:

SqlConnection thisConnection = <connection string)>
thisConnection.Open();
Log.WriteLine(thisConnection.Database);
SqlCommand thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = <SQL query>
SqlDataReader thisReader = thisCommand.ExecuteReader();
while (thisReader.Read())
{
       Log.WriteLine("BarcodeId: " + (String) thisReader["BarcodeId"]);
}
thisReader.Close();
thisConnection.Close();

 

The result from above writes my expected result to the log.  Now, I want to use this result to data bind a test input box further down in the script.  I've tried playing with set/getextracted values, etc.  I know how to do this if extracting an HTML TextContent into a DataBindVariable, but unsure how to do the same with a result from SQL query (coded database step).  Thanks in advance. 

4 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 27 Dec 2016, 11:41 AM
Hi Korey,

If I understand correctly the result is this row of code: 

(String) thisReader["BarcodeId"]

Am I correct?

If so you should put this into an extracted variable. You should add a single row into the While loop:

while (thisReader.Read())
{
       Log.WriteLine("BarcodeId: " + (String) thisReader["BarcodeId"]);
       SetExtractedValue("extractedID", (String) thisReader["BarcodeId"]);
}

When you want to use that variable you should use:

object myData = GetExtractedValue("extractedID");

Let me know if that helps.


Regards,
Boyan Boev
Telerik by Progress
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Korey
Top achievements
Rank 1
answered on 03 Jan 2017, 02:39 PM

Boyan,

Sorry for the late reply -- as I was out for the holidays. 

Thanks for your suggestion.  I'll give it a try. 

 

 

 

0
Korey
Top achievements
Rank 1
answered on 03 Jan 2017, 05:35 PM
This worked great!  Thanks again!
0
Boyan Boev
Telerik team
answered on 05 Jan 2017, 07:38 AM
Hi Korey,

Happy to hear that.

If you need further assistance please let us know.

Regards,
Boyan Boev
Telerik by Progress
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Korey
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Korey
Top achievements
Rank 1
Share this question
or