I cant able to remove a row from a table while running through a loop

Posted by Vibin Jith on Stack Overflow See other posts from Stack Overflow or by Vibin Jith
Published on 2010-04-02T10:00:40Z Indexed on 2010/04/02 10:03 UTC
Read the original article Hit count: 218

Filed under:

I am iterating through the table rows . if the row row is null I just want to remove the row. it shows an error

 Public Sub RemoveBlankRow(ByVal MyDataTable As DataTable)
        Try
            Dim MyRowStr As String = String.Empty
            For Each MyRow As DataRow In MyDataTable.Rows
                MyRowStr = ""
                For Each MyCellText As Object In MyRow.ItemArray
                    MyRowStr = MyRowStr + MyCellText.ToString
                Next
                MyRowStr = Replace(MyRowStr, "0", " ")
                MyRowStr = Replace(MyRowStr, ".", " ")
                If MyRowStr.Trim = String.Empty Then
                    MyDataTable.Rows.Remove(MyRow)
                End If
            Next
        Catch ex As Exception

        End Try
    End Sub

How to overcome this issue?

© Stack Overflow or respective owner

Related posts about vb.net