fguihen Posted December 13, 2005 Posted December 13, 2005 i am trying to enumerate through the primary keys in a table. i create an enumeration like so: System.Collections.IEnumerator e =ds.Tables[table.ToString()].PrimaryKey.GetEnumerator(); i then try to cycle through the items like so: while((e.MoveNext())&&( e.Current != null)) { if(e.Current.ToString() == key) { exists = true; break; } } now i know that there is one entry in the table, but as soon as i call the moveNext method, get an error telling me the ennumeration has already finished. what am i doing wrong? Quote
HJB417 Posted December 14, 2005 Posted December 14, 2005 looks fine to me, try using a foreach out of code simplicity foreach(System.Data.DataColumn column in ds.Tables[table.ToString()].PrimaryKey) { if(column.ToString() == key) { exists = true; break; } } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.