How to compare and find not matching item in two data tables?

Hello. I have two data tables with only a column. Most of the row values are same in both data tables. But some values are only in one data table, and some values are only in other data table. I want to compare this two data tables and get mismatching row values. Here you can see an example of data tables:

DT1 DT2
Title Register Number
67 21
16 34
34 11
21 23
45 45
11 2
23 87

How can I get this mismatching values?

1 Like

have a look here as an introduction to the topic:

also find some starter help here:
Find_Common_NonCommon_By1Col.xaml (12.3 KB)

another option is to work with the dataset operation

3 Likes

Thank you your reply but full join solution is not the solution that I was looking for. I am trying to get mismatching items, not combine all items together.

the join is used for detecting the matchers / non matchers. From the result we can derive it.
The other options are also adressing the same: find matchers / non matchers

we would suggest to go through the different approaches and get the concepts

I see, I am trying to understand both solutions. I think second one will solve my problem. Thank you for these detailed explanations. Have a nice day!

I tried to use second solution, but I get an error like this:

“The source contains no DataRows.”

Column names in my two data tables in different. Do you think this might be the problem?

could be the case of an empty result returned from statement.
Give a try on using the columnnames instead of columnindex.

Feel free to share your xaml with so we can review it. Thanks

I am using output data table and write line activities to see data table and both data tables have values.

How can I specify column names in this code:
dtData1.AsEnumerable.Intersect(dtData2.AsEnumerable, DataRowComparer.Default).CopyToDataTable

I got data tables from excel and sharepoint so even I sent the code, you can’t run it :frowning:

was thinking 2nd approach is the xaml.

Copytodatatable is throwing an exception if returned result is empty. Applying following pattern can handle this defensive:

1 Like

Do you have xaml file for this code?

I found my problem is about mismatching column names. But even I change the column names to the same value with this code:

myDataTable.Columns.ColumnName = “newColumnName”

I got same problem.

may I ask you to have a check on the provided xaml. Here you can refer to the pattern

myDataTable.Columns (YourColumnNameOrIndex).ColumnName = “newColumnName”

refer to the bold part for a working statement

Oh, I pasted the code wrong. I used same code as you. On write line activity column name seemed like it changed, but I still got same error. I don’t know why. I will try other code you shared.

Thank you, second code works even the column names are different.

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