How to Isolate Data process

Class library usage, coding and language questions.
omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

How to Isolate Data process

Post by omayer » Wed Dec 12, 2012 7:32 pm

Currently I do have usercode module to read test data from sqlserver using sqlDatareader by row, How do I isolate data processing in different module and pass the value to other module , so execution module will not do the data processing, Thank you in Advance

Code: Select all

#region |Method- CreateTordr(string _businessUnit)|

     public void CreateTordr(string _businessUnit)
           
      {
        
            try
            {
               _jobConn.Open();
               
            }
            catch(Exception e)
            {
               Report.Failure(e.ToString());
            }
            
              SqlDataReader myReader = null;        
    
        cmdScenarioId.Parameters.Add(new SqlParameter("businessunit", _businessUnit));
              myReader = cmdScenarioId.ExecuteReader();

             while(myReader.Read())
             {
             
              _businessUnit= myReader["businessunit"].ToString();               

          tempInformation.SelectBusinessUnit(_businessUnit.Trim());
            
      #endregion
   
Tipu

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

Re: How to Isolate Data process

Post by Support Team » Thu Dec 13, 2012 1:48 pm

Hello,

You could make a 'SQL connector' class to get your data from your database.
Please take a look at our API documentation about 'SQL Data Connectors'.
Please take a look at this post in our forum.

Then, you need to create an instance of this class and use its methods as shown below:
SQLconnector myConn = new SQLconnector()
myConn.RunQuery(string SQL);
Could you please clarify what you want to do?

Regards,
Markus (T)

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: How to Isolate Data process

Post by omayer » Thu Dec 13, 2012 9:01 pm

Thank you Markus, I am trying to read testdata from sql database and then pass as parameter to Method

candidate.firstname(fname) ----i like to get the fname from candidate table and firstname column.

-- Currently i am retrieving data on execution , i want data retrieved in separate class.
say i want to create 10 user, ( user fname will read from sql db) , how to read 1st row then pass the fname to caller , then creating 2nd user will get the fname from 2nd row.

SqlDataReader myReader = null;

cmdScenarioId.Parameters.Add(new SqlParameter("businessunit", _businessUnit));
myReader = cmdScenarioId.ExecuteReader();

while(myReader.Read())
{

_businessUnit= myReader["businessunit"].ToString();

tempInformation.SelectBusinessUnit(_businessUnit.Trim());
Tipu

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

Re: How to Isolate Data process

Post by Support Team » Mon Dec 17, 2012 5:03 pm

Hello,

I am not sure if I quite catch your issue, but you could make a UserCodeModule where you implement the method which retrieve the data from the sql database. You can call this method every time you want to get some values from the database.
Please check the following link to get more information about creating classes in C#:
http://www.programmersheaven.com/ebooks ... _ebook.pdf
http://www.homeandlearn.co.uk/csharp/csharp.html
You can find a little tutorial how to access data in a sql database at the following link:
http://www.codeproject.com/Articles/441 ... -through-C

Regards,
Bernhard

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: How to Isolate Data process

Post by omayer » Mon Dec 17, 2012 10:18 pm

Thank you for the reference links, these are very helpful. I was trying to read the entire table first then read from the holding place wherever I needed.
Tipu

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

Re: How to Isolate Data process

Post by Support Team » Tue Dec 18, 2012 9:29 am

Hello,

I'm not sure if the problem is solved now.
Please let me know if you could solve this issue.

Regards,
Bernhard

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: How to Isolate Data process

Post by omayer » Wed Dec 19, 2012 5:19 pm

Sorry i could not solve the issue, I want to create DataProcess class that will read entire data from table in sql db , Then another class will be like order class which will retreived data from DataProcess class as needed. Thank you in Advance
Tipu

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

Re: How to Isolate Data process

Post by Support Team » Thu Dec 27, 2012 11:47 am

Hello,

Could you please explain which steps you followed to solve your issue?
What exactly is not working?

We could not provide you with a code example for your use case since it is not a Ranorex specific issue.
You could use Linq in order to simplify data access. Please take a look at Linq in MSDN.
A few examples for Linq are shown here.

Regards,
Markus (T)

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: How to Isolate Data process

Post by omayer » Fri Dec 28, 2012 4:10 pm

Thank you Markus, using Linq solved the problem
Tipu

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

Re: How to Isolate Data process

Post by Support Team » Fri Dec 28, 2012 4:26 pm

Hello,

You are welcome :-)

Regards,
Markus (T)