So, I have to rows in my DataSet;
Row One - has field names.
Row Two - has field values.
I have one Dictionary
I use foreach loop, to retrieve the field names for the Row One.
Only after I have fetched all the field names from row, I can go to the second row (Row Two) with the - foreach - loop.
Here, I want to fill all the field names, then in my second iteration can fill all the field values into the same Dictionalry object.
But Dictionary does not allow me to fill null value in the second cell.
I don't want to use Array because I can't know the size of columns in any given row, they change.
My sample test case also attached.
--------------------------Code -----------------
public void CodedUITestMethod1()
{
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$]");
cmd.ExecuteNonQuery();
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
dataAdapter.SelectCommand = cmd;
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
DataRow[] foundRows = ds.Tables[0].Select("TestCaseID Like 'Two%'");
Dictionary
//Row iteration
foreach (DataRow dr in foundRows)
{
//Column iteration within the row
foreach (Object c in dr.ItemArray)
{
//Storing column value into dictionary
dictionaryObj.Add(c.ToString(), "");
}
}
}
VulpesPosted Aug 30, 2014, 10:00 AM
However, if the first row contains the field names and the second row contains the field values, then I'd try populating the dictionary using this code:
OneA OnePosted Aug 30, 2014, 11:52 AM
Really thanks a lot, it solved my problem!
Have been struggling with this for the past 6-8 hours - Thanks again!
I assume you are a C# developer.
I am a tester, learning C# just now.