TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
OneA One
NA
12
2.7k
Store null value into Dictionary.
Aug 30 2014 9:19 AM
I use DataSet and DataRow to retrieve values from XLS.
So, I have to rows in my DataSet;
Row One - has field names.
Row Two - has field values.
I have one Dictionary<string, string> l = new Dictionary<string, string>();
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<string, string> dictionaryObj = new Dictionary<string, string>();
//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(), "");
}
}
}
Reply
Answers (
2
)
Passing mysq query and run cryreport
c#