Site Search:
Sign in | Join | Help
4Penny.net

VB.NET

Notes, Tricks and Tips on VB.NET

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
 

Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add