Site Search:
Sign in | Join | Help

This Blog

Syndication

VB.NET

Notes, Tricks and Tips on VB.NET

September 2007 - Posts

  • Deleting Rows from a DataSet

    Here is a trick I found while trying to delete rows from a DataSet.  I first tried the following code, but it throws an exception because the enumerator has changed.

     For Each dr As DataRow In ds.Tables(0).Rows
            If CType(dr("Rate2"), Double) = 0.0 Then
                    dr.Delete()
            End If
    Next
     

    By changing the collection into a select statement, it gets around the exception. 

     For Each dr As DataRow In ds.Tables(0).Select()
            If CType(dr("Rate2"), Double) = 0.0 Then
                    dr.Delete()
            End If
    Next