DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Tue, 21 Aug 2007 06:14:08 -0700,    posted on: microsoft.public.dotnet.framework.adonet        back       

Thread Index
  1    Jörgen
          2    Patrice http://www.chez.com/scribe/
          3    Jörgen


Saving of deleted rows   
I have a form with master/child tables. I Deleted a row in the child table 
with datarow.Delete and tried to save the change to the database. Because I 
have a Foreign Key constraint between the tables I must make updates in a 
certain order
1. Child Deletes
2. Master Updates/Deletes/Inserts
3. Child Updates/Inserts

When I try to Save the Child Deletes to the database via the dataadapter i 
get the following error:

InvalidOperationException:
The Collection has changed
in swedish: Mängden har ändrats. Det är inte säkert att uppräkningen kan 
genomföras.
   vid System.Data.RBTree`1.RBTreeEnumerator.MoveNext()
Det finns ingen rad på positionen 0.

I tried a for each datarow in datatable loop and the exception is thrown at 
the next command after the first datarow is saved.

It seems that you can't move to the next row in the collection after the 
deleted row is saved to the database.

Does anybody have a workaround for this problem?
Date:Tue, 21 Aug 2007 06:14:08 -0700   Author:  

Re: Saving of deleted rows   
Likely because you can't browse a collection with "for each" if you change 
the collection.

The usual way to handle this is to use the index from count-1 to 0 so that 
deleting an element doesn't make you skip over an element.

As a side note (and if I remember) you can also use the Update method on the 
datatable so that you don't have to browse for records but sill handles in 
which order tables are updated...
---
Patrice

"Jrgen"  a crit dans le message de news: 
A9362791-1244-4D98-A5B7-EAC77305B1C9@microsoft.com...

>I have a form with master/child tables. I Deleted a row in the child table
> with datarow.Delete and tried to save the change to the database. Because 
> I
> have a Foreign Key constraint between the tables I must make updates in a
> certain order
> 1. Child Deletes
> 2. Master Updates/Deletes/Inserts
> 3. Child Updates/Inserts
>
> When I try to Save the Child Deletes to the database via the dataadapter i
> get the following error:
>
> InvalidOperationException:
> The Collection has changed
> in swedish: Mngden har ndrats. Det r inte skert att upprkningen kan
> genomfras.
>   vid System.Data.RBTree`1.RBTreeEnumerator.MoveNext()
> Det finns ingen rad p positionen 0.
>
> I tried a for each datarow in datatable loop and the exception is thrown 
> at
> the next command after the first datarow is saved.
>
> It seems that you can't move to the next row in the collection after the
> deleted row is saved to the database.
>
> Does anybody have a workaround for this problem? 
Date:Tue, 21 Aug 2007 15:41:28 +0200   Author:  

Re: Saving of deleted rows   
"Patrice" wrote:


> Likely because you can't browse a collection with "for each" if you change 
> the collection.
> 
> The usual way to handle this is to use the index from count-1 to 0 so that 
> deleting an element doesn't make you skip over an element.
> 
> As a side note (and if I remember) you can also use the Update method on the 
> datatable so that you don't have to browse for records but sill handles in 
> which order tables are updated...
> ---
> Patrice
> 

In my original code that caused the exeption the save function in my dalc it 
is boiled down to DataAdapter.Update(DataTable) and this still causes the 
InvalidOperationException.
Date:Tue, 21 Aug 2007 07:00:03 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us