Need help with iterating through Dictionary>

I am trying to create unique records for data I have pulled from a MySql database, initially this seems to work fine. However when I try to output the List<string> data I keep ending up with blank or Null values. I am expecting the List<string> temp = i.Value; to hold the hold each records values but no results. Any suggestions are appreciated!

 

int count = 0; Dictionary<int, List<string>> recordValues = new Dictionary<int, List<string>>(); List<string> values = new List<string>(); foreach (DataRow row in data.Rows) { foreach (DataColumn col in data.Columns) { values.Add(row[col].ToString()); } recordValues.Add(count,values); values.Clear(); count++; } foreach (KeyValuePair<int, List<string>> i in recordValues) { List<string> temp = i.Value; foreach (string s in temp) { CreateTextBox(s); } } 

EDIT:

 

I also tried just one record with no output.

 

List<string> temp1 = new List<string>(); recordValues.TryGetValue(1, out temp1); for (int i = 1; i < temp1.Count; i++) { CreateTextBox(temp1[i]); } 

by xxsiriusxburnxx via /r/csharp

Leave a Reply