Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Posted

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;
}
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...