Finding orphans among two datatables
Hi -- I've got two datatables with identical structures. I want to be able to find all of the values in one column in one of the datatables that are not in the same column in the other datatable. The values that don't match should be put into a third datatable. This is what I've got so far.
Dim dtOuter As DataTable
Dim dtInner As DataTable
Dim dtOrphans As DataTable
'Code to populate datatables omitted.
For Each row As DataRowView In dtOuter.DefaultView
Dim dv As New DataView(Table:=dtInner, _
RowFilter:="widget_name = '" & row("widget_name").ToString & "'", _
Sort:="", _
RowState:=DataViewRowState.CurrentRows)
If dv.Count = 0 Then
Dim newrow As DataRow = dtOrphans.NewRow
newrow("widget_name") = row("widget_name").ToString
dtOrphans.Rows.Add(newrow)
End If
Next
Problem is, the two datatables can have over 1,000 rows and this loop takes a long time to finish processing. Is there a more efficient way to perform this task?

