« .NET spelling | Main | 700 spam a month »

July 09, 2005

More on DataRow deletion

I discovered another way for looping through a collection while removing the entries, thanks to a colleague, the trick is to loop through from the end of the collection. This way current item removed is always the last item, thus does not affect the current iteration, quite nifty really:


for (int i = dataSet.Table.Rows.Count - 1; i >= 0; i--)
{
    DataRow row = dataSet.Table[i];
    if (row ... )
    {
        row.Delete();
    }
}

Update: Crap bad coding .. my bad :) Fixed now

Posted by vhadiant at July 9, 2005 10:53 AM





Trackback Pings

TrackBack URL for this entry:
http://www.hadianto.net/mov32/mt-tb.cgi/67

Comments

Post a comment





Remember Me?

(you may use HTML tags for style)