Best way to check if a data exists in a data table

I have two data tables like this

image

I want to check if (Emp Code+Name) in dt 1 exists in dt 2

I want to check if the item array exists

What is the best way to achueve this?

Kindly help…

Thanks
Valli

@shaik.muktharvalli1

You want to check the column names or you want to compare the rows of dt1 with dt2

Hi @shaik.muktharvalli1

I am getting a little bit confusion in your query, Could you be more elaborate your query and better to provide an example by showing two datatables look like.

this is my already existing DB:
image

my next DB like:
image

Need out put like:

image

Need to check if item array exist or not if exist do nothing , if not exist then append

@shaik.muktharvalli1

Please try this in assign

dt = dt.AsEnumerable.Union(dt1.AsEnumerable,DataRowComparer.Default).CopyToDataTable

cheers

can you share Sample workflow please?

@shaik.muktharvalli1

As already mentioned

dt is first file and dt1 is second file

cheers

1 Like

let me check and confirm @Anil_G

1 Like

Hi,
Input:-
Dt1

Dt2

Output:-

Xaml File:-
Main.xaml (12.2 KB)

Thanks

Okay @shaik.muktharvalli1

You can use the below LinQ Expression,
→ Use the Read range workbook activity to read the Excel1 and store in a datatable called Dt1.
→ Use another Read range workbook activity to read the Excel2 and store in a datatable called Dt2.
→ Use assign activity to write the LinQ Expression,

- Assign -> dt_Output = Dt1.AsEnumerable.Except(Dt2.AsEnumerable, DataRowComparer.Default).Select(Function(row) row).CopyToDataTable

→ After assign activity use the Append Range workbook activity to append the excepted results in Excel1.

Check the below workflow for better understanding,

Hope it helps!!

Check the output below for better understanding… @shaik.muktharvalli1
image

Hope you understand!!

If dt already existed , in dt1 same data present then have to check and remove duplicate entries if not then append into existed dt

It checking only one column , But I have to check all columns

If Name cloumn values same but Emp code value different then have to append

If both same compare to Existed DB then don’t append it

Do you want to check every column or you want to check only one particular column as you mentioned above Name column.

Could you be more specific… @shaik.muktharvalli1

Need to check all columns (Emp Code+Name)

Thnaks
Shaik

This xaml will check in all columns. It will match row values.

Thanks

@shaik.muktharvalli1

Simple would be to use a merge datatable and then use a remove duplicates activity

cheers

1 Like

I was about to post the same thing. Merge datatable, remove duplicates. Simple.

1 Like