Compare only first three columns of two data table

Hi All,

  • I had two collections in which the data-tables are stored, Now I need to compare the datatables based on the count of number of rows.

Can anyone please suggest of how to compare only first three columns of two datatables.

We can get the first three columns of a datatable alone
Datatable = Datatable.DefaultView.ToTable(False,”columnname1”,”columnname2”,”columnname3”).CopyToDatatable()

Then the same for another datatable as well
And followed by that use JOIN datatable activity for comparing

Cheers @Shivaraju

1 Like

Thanks @Palaniyappan
I will check and update you.

1 Like

@Shivaraju
In Case of you need more Help Just provide us sample Data of the source Data and the expected result. So WE can quickly Help you on the Statement development

1 Like

Thank you @ppr,
Please check the below image and provide the necessary code to get the Expected result.

@Shivaraju
can you crosscheck the table
dt1: AA,BB,10 is matching 3 cols in dt2 AA BB 10 but is not in your result list
dt1: CC DD 30 is not matching 3 cols in dt2

so i have some difficulties to derive your result table. Can you please help on this?

1 Like

@ppr
I need to compare datatables of same row and if it is not same then get those records in another datatable. My requirement is to get the Not Matched Records in the Datatable. Hope you are clear about my requirement.

@Shivaraju
does mean:
comparision will be done on the column string1, string2, Value
if dt1 row based on the compair is not contained in dt2 then the row is part of the result

looks close to this:

does mean find the common rows between dt1 and dt2 based on the 3 columns
Identify the which of the dt1 rows are not part of the common rows (doing this with an except statement)

In case you need more help on the statement let me know. On later time I can setup a sample for you.

1 Like

@Shivaraju
give a try similar to referenced post from above

irst Assign:
(From t1 In dt1.AsEnumerable
Join t2 In dt2.AsEnumerable
On t1(“string1”).ToString.Trim Equals t2(“string1”).toString.trim And t1(“string2”).ToString.Trim Equals t2(“string2”).toString.trim And t1(“Value”).ToString.Trim Equals t2(“Value”).toString.trim
Select t1).CopyToDataTable

second Assign:
dt1.AsEnumerable.Except(dtCommon.AsEnumerable,DataRowComparer.Default).CopyToDataTable

Let me know the result, Thanks

2 Likes

Thanks @ppr,
I had checked the above thread, but didn’t find my appropriate solution.
Let me explain my scenario once again,
In Datatable1, “string1” column is to compare “string1” column in Datatable2
i.e.,First row–> AA-AA,BB-BB,10-10 all are matched.
Second row–> BB-BB,CC-CC,20-30 not matched.

@Shivaraju
Sorry I didnt get you, but can check code from post above in which i adopted the code to your scenario

2 Likes

@ppr
If the first three columns of two datatables are same then this code raises an error.
dt1.AsEnumerable.Except(dtCommon.AsEnumerable,DataRowComparer.Default).CopyToDataTable
The above code applies only to different datatables.

@Shivaraju
just provide some more details on error, xaml or screenshot
Keep in mind. CopyToDataTable will throw an error if there are no rows in the returned result.

1 Like

@ppr
Please find the attached file and provide the xaml fileSampleDatatable.xlsx (9.6 KB)

@Shivaraju
can you check at your end change 3rd column name from value to fiberscount

1 Like

@Shivaraju
it was the columnname as it was different in the excel
FYI - go for debug and integrate it in your code Shivaraju.xaml (7.5 KB)

1 Like

Thank you very much bro @ppr
How to avoid the error of CopyToDataTable, if there are no different rows in the datatable.

@Shivaraju
not using CopyToDataTable and get returned the rowcollection (may you crosscheck the excact Datatype)
then using in an if else the count information on this
if there are rows then do the CopyToDataTable

1 Like

Thanks bro @ppr you helped me a lot.

@Shivaraju

just for initial help
Assign drDiff = dt1.AsEnumerable.Except(dtCommon.AsEnumerable,DataRowComparer.Default)