How to write data in data table

Best practices, code snippets for common functionality, examples, and guidelines.
Posts: 15
Joined: Mon Apr 25, 2016 7:54 pm

How to write data in data table

Post by ninaddande » Tue Apr 26, 2016 11:07 pm

Hi Folks,

I have create a data table named xyz as a data source with 3 columns in it and one row with blank values. I want to assign values in row 1 of the data table for all 3 columns from my first test case where I am creating a user and I get values like userName, Password etc. Could you please tell me programatically how can I enter values in a data table.

I tried to do it this way:
Report.Info ("get data source");
var dataConn = DataSources.Get("DetailsTable");

//add rows to the data source with your specific data/values
Report.Info ("add rows with customized data to the data source");
dataConn.Rows[0].Values[0] = "32432fsf";
dataConn.Rows[0].Values[1] = "sdsadsads";
dataConn.Rows[0].Values[2] = "thgrfhh";
//data source needs to be stored before used by the following Test Case
Report.Info ("store the data source");

However I dont know what exactly I am missing as values are not being updated in the table.
Could you please guide?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA

Re: How to write data in data table

Post by Support Team » Mon May 02, 2016 12:36 pm

Hi Nina,

Unfortunately, I'm not exactly sure if I understood your intention correctly, but if you want to add content to an existing data source with existing columns you could use the code below.
var connector = DataSources.Get("YourConnector");
Ranorex.Core.Data.Row row = new Ranorex.Core.Data.Row(new string[] {"YourValue","YourValue1","YourValue2"});
It is important to run this code before you start the proper TestCase (previous TestCase), because the data table gets loaded before the TestCase starts.
Please note that the content of the data source is only accessible during runtime. That means that after the execution has finished the data source is empty again.

I hope this solves your problem.

Kind regards,