0

I have a dictionary variable having two values which I have retrieved from the DB. I need to update the values in the DB and while updating I need to check whether the updated values exists in the dictionary values or not. How can I compare. So far I have done this much. Please help me whether this is right or wrong.

Retrieving the datas from the DB and stoing it in Dictionary variable "DictionaryName"

For Each row As DataRow In ds.Tables(0).Rows
    DictionaryName.Add(row("EngMemID").ToString(), row("EngMemEmail").ToString())
Next

After this I have to compare it with my mew value.

        Dim pair As KeyValuePair(Of String, String)

        For Each pair In DictionaryName
            If DictionaryName.ContainsKey(newMember.EngMemID) Then
                ---Condition to compare the EmailID's 
                    NotifyOnUpdate(newMember)
                ---
            End If
        Next

After comparing the ContainsKey(), how can I compare the old and new Email Id's.

Please help me to compare these two values, from the Dictionary with the new value.

Thanks,

Udhaya S.

4

3 回答 3

2

尝试这个

 Dim oldValue As String
 If memberEmaillList.TryGetValue(EngMemID, oldValue) AndAlso oldValue <> EngMemEmail Then
        NotifyOnUpdate(newMember)
 End If
于 2013-08-13T12:23:47.790 回答
1

您不需要循环所有成员,只需使用 ContainsKey

If memberEmaillList.ContainsKey(newMember.EngMemID) Then
    engMemEmail = memberEmaillList(newMember.EngMemID)

    ' Key exists, engMemEmail is the value attached to the key
Else
    ' Key does not exists
End If
于 2013-08-13T12:43:17.297 回答
0

这是 C#

if(memberEmaillList.ContainsKey(newMember.EngMemID))
{
     if(string.comare(memberEmaillList[newMember.EngMemID],newMember.EmailAddress,true) == 0))
     {
        //have match
     }
     else 
     {
        //no match
     }
}
于 2013-08-13T12:34:59.787 回答