Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / January 2006

Tip: Looking for answers? Try searching our database.

Removing elements from a typed dataset

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ayoa - 10 Jan 2006 17:58 GMT
I have the following code whose purpose is to take 2 typed datasets (of type
DSAccounts )  & remove all elements of one from the other. and return what
is left.

However I am getting the error message "The given datarow is not in the
current DataRowCollection" when the "dtAll.tblAccounts.Rows.Remove(dr);"
line executes. I have debugged and found that the data to be deleted is
definitely present in the master dataset.

What am i doing wrong?? Please help!

private DSAccounts RemoveFromDS(DSAccounts dtAll, DSAccounts dtRemove ) {

try {

string account;

foreach (DSAccounts.tblAccountsRow dr in dtRemove.tblAccounts.Rows)  {

account = dr[0].ToString();

if (dtAll.tblAccounts.Rows.Contains(account))

       dtAll.tblAccounts.Rows.Remove(dr);

}

return dtAll;

}

catch (Exception e) {

throw e;

}

}
Sericinus hunter - 10 Jan 2006 19:03 GMT
   When you iterate a collection with foreach loop you cannot add or remove
collection elements. Try using 'for' loop instead, counting from Rows.Count-1 to zero.

> I have the following code whose purpose is to take 2 typed datasets (of type
> DSAccounts )  & remove all elements of one from the other. and return what
[quoted text clipped - 34 lines]
>
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.