Compare two datatable Write Status

Hi Team,

i have two datatable to compare

use this linq
“Dt_Sh1.AsEnumerable.Except(Dt_Sh2.AsEnumerable(),System.Data.DataRowComparer.Default).CopyToDataTable” and get output but i want write the status columns which columns is not match… Can tell me how to write the status.

Thank
shyam

@Shyam_Pragash

This query will not work
Can you provide any sample input and output

Cheers

@Shyam_Pragash

Try this

  1. Add a status column to dt1
  2. Use invoke code with dt1 as in/out argument and dt2 as in argument
  3. dt1.AsEnumerable.ToList.ForEach(sub(r) r("Status") = If(dt2.AsEnumerable.Any(function(x) x.ItemArray.Equals(r.ItemArray)),"Matched","Not Matched"))

cheers

Hi @Anil_G

i am getting error

@Shyam_Pragash

Did you add dt2 as only in parameter or in out?

Please set argument direction as in

cheers

Hi,

Can you try the following sample?

listStatus = dt1.AsEnumerable.Zip(dt2.AsEnumerable,Function(r1,r2) String.Concat(Enumerable.Range(0,dt1.Columns.Count).Select(Function(i) if(r1(i).ToString=r2(i).ToString,"",dt1.Columns(i).ColumnName+";")))).ToList

Then add datacolumn
Next

dt1 = dt1.AsEnumerable.Zip(listStatus,Function(r,s) dt1.Clone.LoadDataRow(r.ItemArray.Take(dt1.Columns.Count-1).Concat({if(s="","Match",s+" NOT Match")}).ToArray,False)).CopyToDataTable

Sample20230928-6L.zip (9.3 KB)

Regards,

@Shyam_Pragash

As mentioned please change dt2 to in only and not in/out

cheers

Hi @Yoichi

As per your sample input working fine…

But Uneven of rows of sheet1 and sheet2 but getting wrong output…

Hi,

Can you share input data as file?

Regards,

Hi @Yoichi

i have 45 columns some data… but can’t share you…

Only Two columns of input data shared you.

Input.xlsx (9.0 KB)

Thanks
Shyam

HI,

This data doesn’t seems same as the following which you uploaded in previous post.

Can you also share expected output for the above input?

Regards,

Hi @Yoichi

for Understanding purpose i share.

On Input based how to write the status columns…

i expected output in status columns

Hi,

As Sheet1 has 14 rows and Sheet2 has 15 rows, it’s difficult to compare items of same row number.
If you don’t need to compare items of same row number, it’s difficult to find which item is different.

Regards,

Hi @Yoichi

Okey Thanks

On Your previous code… can able check multiples columns in a sheet1 and sheet1 ?

Thanks
Shyam

HI,

Yes, it can handle multiple columns. Please note that it compares items at same row number and same column number.

Regards,

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