Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Delete row in dataview
Message
De
09/09/2005 20:54:55
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01048268
Message ID:
01048341
Vues:
19
Einar,

The foreach (and also iterating forward through the view instead of backwards), causes problems because you are deleting rows and once a row has been marked as Deleted, it no longer belongs to the DataView (because DataViews typically exclude Deleted rows). It totally gets the foreach all confused.

As far as saying drv.Delete() versus using drv.Row.Delete(), it doesn't matter ... you end up deleting the same object.

~~Bonnie


>Bonnie,
>I thought about using a for instead of a foreach also (I swear I did <s>), but I can't understand why a foreach will not work for this. I guess I should set off some time this afternoon to acctually test it :)
>
>Are you sure the .Row should be in there? (Again I haven't tested the code, cuz I am working in Borland today :( )
>
>
>Einar
>>You need to do it in reverse order, so you'll need to iterate with for rather than use foreach:
>>
>>DataRowView drv;
>>for(int i= goView.Count-1; i >=0; i--)
>>{
>>    drv = goView[i];
>>
>>    if (drv["userid"].ToString().Equals("DSMI"))
>>    {
>>        drv.Row.Delete();
>>    }
>>    else
>>    {
>>        drv["userid"] = drv["userid"].ToString() + "Kretek";
>>    }
>>}
>>
>>
>>~~Bonnie
>>
>>
>>>I had tried that, I got there is no row at position 134. Same error as doing it the other way. Do I need to accept the changes, is that why its giving me an error.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform