Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Delete Row
Message
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Titre:
Divers
Thread ID:
01459084
Message ID:
01459087
Vues:
55
>It's a very simple problem and should be listed in the foreach command reference. You can not remove member of a collection while enumerating it.

I agree.

This works, although it seems bass ackwards:
public void ClearDataStore(string DataViewName)
{
    DataViewName = DataViewName.ToString().ToLower().Trim();

    DataTable dt = _dsDataStore.Tables[0];

    for(int i = dt.Rows.Count - 1; i >= 0; i--)
    {
        DataRow dr = dt.Rows[i];

        string dtItem = dr["DataViewName"].ToString().ToLower().Trim();

        if (dtItem == DataViewName)
        {
            dt.Rows.Remove(dr);
        }
    }

    _dsDataStore.Tables[0].AcceptChanges();
}
>
>See Re: MisUnderstanding FOR EACH Thread #1329767 Message #1329799
>
>>This seemingly simply process is throwing the error:
>>
>>
>>Collection was modified; enumeration operation might not execute.
>>
>>
>>Here's the code:
>>
>>
>>public void ClearDataStore(string DataViewName)
>>{
>>    DataViewName = DataViewName.ToString().ToLower().Trim();
>>    
>>    foreach (DataRow Row in _dsDataStore.Tables[0].Rows)
>>    {
>>        if (Row["DataViewname"].ToString().ToLower().Trim() == DataViewName)
>>        {
>>            Row.Delete();
>>        }
>>    }
>>
>>    _dsDataStore.Tables[0].AcceptChanges();
>>}
>>
>>
>>What's the right way to remove rows from a DataSet????
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform