ennumerator problems

fguihen

Junior Contributor
Joined
Nov 10, 2003
Messages
248
Location
Eire
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:

Code:
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?
 
looks fine to me, try using a foreach out of code simplicity

Code:
foreach(System.Data.DataColumn column in ds.Tables[table.ToString()].PrimaryKey)
{
	if(column.ToString() == key)
	{
		exists = true;
		break;
	}
}
 
Back
Top