I need to do some comparing and shuffling of fields, (i come from a more PHP background and working with arrays is completely different, as suggested after readin many things here I know VB.NET uses LIST and Dictionary easier.
I have a dictionary (of string, dictionary (of string,string)) which is filled well, but after I try to read it out, it’s always empty….
below I fill a few things. The var I am talking about it
fillDictionary inside the matcheswholename VALUES part.
I fill up the fillDictionary and add it to the matchesWholename
Afterwhich I clear it, because it is in a loop and more is to come.
Dim matchesTotal As New List(Of String)
Dim fillDictionary As New Dictionary(Of String, String)
Dim matchesWholename As New Dictionary(Of String, Dictionary(Of String, String))
Try
If ds.Tables("matchesWholename").Rows.Count > 0 Then
For Each dr As DataRow In ds.Tables("matchesWholename").Rows
If Not matchesWholename.ContainsKey(CStr(dr("key"))) Then
fillDictionary.Add("programme", CStr(dr("programme")))
fillDictionary.Add("remark", CStr(dr("remark")))
fillDictionary.Add("key", CStr(dr("key")))
fillDictionary.Add("displayname", CStr(dr("prop_value")))
Console.WriteLine("count before insert {0}", fillDictionary.Count)
matchesWholename.Add(CStr(dr("sanction_key")), fillDictionary)
End If
If Not matchesTotal.Contains(CStr(dr("key"))) Then
matchesTotal.Add(CStr(dr("key")))
End If
fillDictionary.Clear()
Next
End If
Catch ex As Exception
Console.WriteLine("Err: {0}", ex.Message)
End Try
When later I try to readout like this, it returns nothing….
I am actually sending a copy of the filldictionary into it or not? or does my clear() method clear what’s inside it?
Dim pair As KeyValuePair(Of String, Dictionary(Of String, String))
Dim subpair As KeyValuePair(Of String, String)
For Each pair In matchesWholename
' Display Key and Value.
For Each subpair In pair.Value
Console.WriteLine("{0}, {1}, {2}", pair.Key, subpair.Key, subpair.Value)
Next
Next
fillDictionary.Clear()looks somewhat suspicious. You’re essentially clearing the dictionary each iteration of yourForloop.