Comparison of CSV files and storing similar and different records in different csv files

csv
studio

#1

Hi All,

My objective is,

  1. Compare 2 CSV files.
  2. Store similar records in similar.csv
  3. Store different records in different.csv

I am trying to do following things:

  1. Read 2 CSV files.
  2. Build 3 blank data tables for storing output and temp usage. DT1, DT2 and DTunion.
  3. Do sort and distinct values so that I dont compare same records again and again (Just for code efficiency).
  4. [Temporary step] Store both the csv file records in one single datatable DTunion. (kind of union set).
  5. Nested for each row and if condition inside to check if the record is same or not. if yes, “add data row” to datatable DT1. [This step gives me clear list of similar records. So, this step is fine and need no changes.]
  6. For different records, I am simply removing distinct records from union set. [Union - Distinct = Different]. For this, Started generic For each on DT1.Rows and invoked a method called Remove on DTunion.Rows. This should ideally remove DT1.Rows (distinct rows) from DTunion.Rows (Union of rows). However, it is throwing error “DataRowCollection does not have a public instance method named ‘Remove’ matching the parameter types, generic type arguments, and generic type constraints supplied to InvokeMethod ‘Invoke Method’.”

Please help with sample xaml or update my xaml.


#2

If you are comparing on a column name then this sample should help.(been a while did not test it)

  1. Similardt - Common Records
  2. missingdt1 - Records exists in dt1 but not in dt2
  3. missingdt2 - Records exists in dt2 but not in dt1
  4. merge missingdt1 and missingdt2 in missingdt1

you can write #1 and #4 to csv.

dtCompare.xaml (14.0 KB)


#3

Thank you for your prompt reply. The solution is working.