I have a microsoft visual basic collection (in the namespace Microsoft.VisualBasic) – which uses the Microsoft.VisualBasic.Dll library.
private Collection myCollection;
When i add values to it, I get the following error:
Add failed, duplicate key cannot be inserted
How do i handle that? I need to pass all the ID’s. For example, if have a collection of ID’s (e.g. 10, 11, 12, 13, 10), if the code 10 repeats, this line fails:
myCollection.Add(myIDs.ID); // this code throws exception
http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.collection.aspx
Before you add, check to see if the collection already contains the key.