Compare between 2 CSV file (not excel)

I have 2 CSV files (not excel) and both the files have 4 columns

FileA (Datatable DT1)

Name, Price, Name1,Price1
Mango,20,frooti,10
Orange,30,Juce,10

FileB (Datatable DT2)

Name, Price, Name1,Price1
Mango,20,frooti,15
Orange,40,Juce,10

I am trying to add result after each price and pass True or False depending on Match

I am bit confused how to write the IF condition under For Each Row

Can anyone help :pray:

Hi @dipon1112000

Do you want to compare all the columns of each row or any any one column

Only the price columns

I e price and Price1 between 2 files as there is change expected

@dipon1112000 ,

Show the expected output.

Thanks,
Ashok :slight_smile:

inside for each

Dim matchingRows() As DataRow = dt2.Select(“Name = '” & row1(“Name”).ToString() & “'”)—get the matching rows from both the table

if matchingRows.length>0
price2=Convert.ToDouble(matchingRows(0)(“Price”)—get the price from matching row

check if price2=row1(“price”)-to check if the price matches

@dipon1112000

If you use for each in for each then it will iterate multipletimes while checking
Instead it you can linq query as below
Output.txt (90 Bytes)
DT1.txt (64 Bytes)
DT2.txt (64 Bytes)

Sequence1.xaml (10.1 KB)

Assign: DT1 = (From row1 In DT1.AsEnumerable()
              Let matchFound = DT2.AsEnumerable().Any(Function(row2) row1("Price").ToString() = row2("Price").ToString() AndAlso row1("Price1").ToString() = row2("Price1").ToString())
              Select DT1.Clone().Rows.Add({row1("Name"), row1("Price"), row1("Name1"), row1("Price1"), matchFound})).CopyToDataTable()

Hope it helps!!

hello @dipon1112000
you can try,
Ans_Forum
hope it will help you .
Regards
Dheerandra Vishwakarma

Hi I tried but it is not completing the loop if there is a mismatch. i.e instead it’s throwing an error price is not a part of Datatable

Thank you Lakshmi but I am little confused how to use your code under “For Each Row in Datatable”

  1. Am I using Assign activity for “Dim matchingRows() As DataRow = dt2.Select(“Name = ‘” & row1(“Name”).ToString() & “’”)”

  2. Not sure we’re to use “check if price2=row1(“price”)-to check if the price matches”

Sorry for my ignorance, where are you passing CurrentRow_old, are you using 2 for each row activity?

Did work after few adjustments,

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.