OneA One

OneA One

  • NA
  • 12
  • 2.7k

Dataset - Read XLS (test data) based on some condition.

Aug 30 2014 2:04 AM
I have just started learning Coded UI + C# for my testing. 
I am trying with "DataTable" .
I have stuck at my framework designing for reading test data from XLS. In Java we use ODBC Driver, and it works fine. 
I don't want to use CodedUI default DataSourceAttribute as it does not fit in with our framework.
Here is my XLS file. It has only one sheet - "Sheet1". On this sheet, I put 50 test cases. 
For each test case, 2 rows; 1. Column headers. 2. Test Data/Values.
The Column Headers change for each test case, and this is the problem for me. 
Have been struggling with this for the past 2 days. Any help is great!

 TestCaseName 
 TCOne  Age
 TCOne 19
 TCTwo BankName
 TCTwo ABC Bank
 
 I want to get the Test Data/Values based on the Column Headers.
 My code ( I don't know how to proceed) :

--------------------------- Code ------------------------------------------------------------

 public void readData(){
string filterFilePath = "D:\\songs\\b.xls";
string connectionString = string.Format("Provider = Microsoft.ACE.OLEDB.12.0;Data Source ={0};Extended Properties = Excel 12.0;", filterFilePath);
OleDbConnection con = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand();
con.Open();
cmd.Connection = con;
//cmd.CommandText = String.Format("select * from [Sheet1$] where 'ID =>5' ");
// cmd.CommandText = String.Format("select * from [Sheet1$] where 'TestCase =>One' ");
cmd.CommandText = String.Format("select * from [Sheet1$] where 'TestCase =Two' ");
cmd.ExecuteNonQuery();
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
dataAdapter.SelectCommand = cmd;
DataSet ds= new DataSet();
dataAdapter.Fill(ds);
DataTable dt = new DataTable();
dt= ds.Tables[0];

//string s = "TestCase";
//DataRow foundRow = ds.Tables[0].Rows.Find(s);
DataRow[] foundRows;
foundRows = ds.Tables[0].Select("TestCase Like 'One%'");
string x = dt.Rows[0].ItemArray[0].ToString();
}

---------------------- End of code -----------------------------
Thanks in advance 
 

Answers (1)