运行以下代码时,有时会出现以下错误:
System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Interfaces.InterfaceBase.GetSettings()
我正在使用以下代码:
For Each dr As DataRow In dsData.Tables("tblData").Rows
If InterfaceSettings.ContainsKey(dr("SettingsName").ToString.Trim) = False Then
InterfaceSettings.Add(dr("SettingsName").ToString.Trim, dr("SettingsValue").ToString.Trim)
End If
Next
我在数据库表中没有重复项。知道为什么这会失败吗?
提前感谢您的任何帮助。