Hi,
"Neo The One" <(E-Mail Removed)> wrote in message
news:89F734CF-0BAC-4BF9-BD87-(E-Mail Removed)...
>I need to delete some rows from a DataTable. I am not sure if the
>folllowing
> code is supported:
>
> void DeleteBlankRows(DataTable dt)
> {
> foreach(DataRow dr in dt.Rows)
> {
> if(AllFieldsEmpty(dr)) dr.Delete();
> }
> }
>
> I am wondering if the deletion in middle of foreach will interferer with
> the
> interal enumeration.
Yes, I wouldn't recommend that approach. The thing is that added rows are
actually removed from the list when Delete is invoked on them.
Instead, do a reverse loop (int i = dt.Rows.Count-1 ... i = 0)
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog:
http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group
www.codezone-si.info