I am trying to loop through dictionary of values and then updating row of "MTables" (table Name) fields in 'QvxDataRow MakeEntry()' function through Key values of Dictionary.
i need "MTables" to contain like this
SlNo StudentName StudentClass
1 Daniel 4
2 Maties 4
but in my code i get error for for each loop like below
Cannot convert type 'System.Collections.Generic.KeyValuePair<int, dynamic>' to 'System.Collections.Generic.Dictionary<int, dynamic>
I need to add hardcoded value and put it into row of MTables. I have this
private IEnumerable<QvxDataRow> GetApplicationDB()
{
Dictionary<int, dynamic> map = new Dictionary<int, dynamic>
{
{1, new {SlNo="1", StudentName="Daniel",StudentClass="4"}},
{2, new {SlNo="2", StudentName="Maties",StudentClass="4"}}
};
foreach (Dictionary<int, string> evl in map)
{
yield return MakeEntry(evl, FindTable("ApplicationsStudentDB", MTables));
}
}
private QvxDataRow MakeEntry( evl, QvxTable table)
{
var row = new QvxDataRow();
row[table.Fields[0]] = evl.SlNo;
row[table.Fields[1]] = evl.StudentName;
row[table.Fields[2]] = evl.StudentClass;
return row;
}
How could i do this, Please help me on this.
It's because when you loop through items in a Dictionary, the item within the Dictionary is not a Dictionary, it's a KeyValuePair. You're declaring evl with the wrong type in the loop. Also, your dictionary contains int and dynamic types, but then you declare the loop as a pair of strings. You can't just alter the type like that. It should be:
foreach (KeyValuePair<int, dynamic> evl in map)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With