Results 1 to 11 of 11

Thread: Fastest way to compare two datatables?

Threaded View

  1. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Posts
    144

    Re: Fastest way to compare two datatables?

    Here's my code:
    Code:
    Dim myCON As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\myDB.mdb;Jet OLEDB:Database Password=xxxxxxxxxx"
    
    DT1TableAdapter.Connection.ConnectionString = myCON
    DT1TableAdapter.Connection.Open()
    DT2TableAdapter.Connection.ConnectionString = myCON
    DT2TableAdapter.Connection.Open()
    
    DT1TableAdapter.Fill(DataSet1.DT1)
    DT2TableAdapter.Fill(DataSet1.DT2)
    
    DT1BindingSource.MoveFirst()
    DT2BindingSource.MoveFirst()
    
    For i = 0 To DT1BindingSource.Count – 1
    
        C_ID1 = DT1BindingSource.Current("ID")                
        C_AC1 = DT1BindingSource.Current("AC")
    
        DT2BindingSource.Filter = "ID=" & "'" & C_ID1 & "'"
    
        C_AC2 = DT2BindingSource.Current("AC")
    
        If C_AC1 <> C_AC2 Then
           Dim DRV As DataRow = DirectCast(DT1BindingSource.Item(i), DataRowView).Row
           DataSet1.TempDT.Rows.Add(DRV.ItemArray)
        End If
        DT1BindingSource.MoveNext()
    Next
    End If
    … load the report (TempDT as datasource)
    Please note that I use 'AC' column as a comparison factor because if it is different then all other columns are different as this column represents the total of all other columns' calculations. Also, please note that I need to print all the columns in the report and that's why I load them all with the TableAdapter.Fill

    Thanks
    Last edited by cPubis; Apr 10th, 2015 at 08:17 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width