Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Undo empty row
Message
De
01/09/2007 09:32:14
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
01/09/2007 03:21:34
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01251862
Message ID:
01251872
Vues:
15
>Hi,
>I would like to loop thru datatable.rows and check for any empty row (certain fields are empty). If any, rejectchange.
>
>I try the following code, it complaint "collection was modified". Any other wy to do this?
>
>
foreach(DataRow loRow in DataTable.Rows)
>{
>    if (loRow["MyField"] = string.Empty)
>    {
>        loRow.RejectChanges();
>    }
>}
>
>Please advice.
>
>Thank you

You can't modify a collection with an iterator like foreach. However you could instead use for() in reverse to do that.
for(i=myTable.Rows.Count-1;i>=0;i--)
{
    if ((string)myTable.Rows[i]["MyField"] == String.Empty)
    {
        myTable.Rows[i].RejectChanges();
    }
}
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform