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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.