I am using this code to compare two datatables(myTable and Dtable) and when I find two rows with common data I delete the rows in my other datatable(dtable) so that dtable comes up with data that is not already in myTable. However the code is not doing that at all. what could be wrong with my code

An Example of what I am hoping for is as follows
Datatable1(Dtable)               Datatable2(myTable)                Final Datatable1(Dtable)
brian                                   kelvin                      brian            
kelvin                                  richard                                       
richard


        For Each myRow As DataRow In myTable.Rows
        'Dim filter As String = String.Format("RawMaterialCode='{0}'", myRow("RawMaterialCode"))
        Dim filter As String = String.Format("RawMaterialCode='{0}'", myRow("RawMaterialCode"))
        For Each dRow As DataRow In dTable.Select(filter)
            myAddArray(myTable.Rows.Count) = myRow("RawMaterialCode")
            'dRow.Delete()
        Next
        Next
        dTable.AcceptChanges()



        For Each key In myAddArray
        Dim row = dTable.Rows.Find(key)
        If row IsNot Nothing Then
            'dTable.Rows.Remove(row)
        row.Delete()
        End If
        Next

Edited 4 Years Ago by tendaimare

Best way is to do it at the backend using Cursors. If you want to delete from front end only then you can give this approach
(Assuming you have primary key in your table to indentify unique row.)
Get all the keys into array, and loopthrough them and call the delete procedure or write inline code.

This article has been dead for over six months. Start a new discussion instead.