Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Undo empty row
Message
From
01/09/2007 09:32:14
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
01/09/2007 03:21:34
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01251862
Message ID:
01251872
Views:
17
>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
Previous
Reply
Map
View

Click here to load this message in the networking platform