Hi,
I am using the following code to find whether data in two data tables dt1, dt2 is different, output goes to dtResult. This is throwing an error “System.ArgumentNullException” Can you please help to fix? Thanks a lot,
dtResult=dt1.AsEnumerable().Except(dt2.AsEnumerable(),System.Data.DataRowComparer.Default).CopyToDataTable
Hi @A_Learner ,
Is the Schema of the Datatable the same ? Meaning it has the same columns ?
Also, for the Data supplied, do we get mismatch results or there are no mismatches ?
Check also both the Datatable values by performing a Debug.
1 Like
Thank you,
The code is supposed to detect mismatch.
I verified column names in dt1, dt2 and dtResult to be the same.
@A_Learner ,
We do know the code performs the mismatch, but does the data correspond to it and provide us with the mismatch or are there no mismatches for the data ?
Also, try to avoid direct CopyToDatatable()
after Filtration as mentioned below :
This FirstAid Tutorial will describe how a the source contains no DataRows EXCEPTION can be handled.
Introduction
Let’s have a look at the following filter data table scenario:
Name
CCode
Tom
US
Charlotte
FR
Seema
IN
Jean
FR
Assignment:
Filter all rows on a particular Country Code like FR, UK, ES, UK…
Ensure that all CCode data column values are trimmed
Ensure that the Filter check is case insensitive
we can implement it e.g. with the help of a LINQ statement:
dtData.As…
Anil_G
(Anil Gorthi)
August 11, 2023, 2:24pm
5
@A_Learner
As per error looks like all are matching your except is not returning any data
Before doing copydatatable use .Count>0 in if condition and on then side use copytodatatable and on else side it means there is not even one row
Cheers
Thank you, @supermanPunch for the pointer.
Changed the code slightly. Still getting error “Value cannot be null” at the assignment activity.
dataRow = dt1.AsEnumerable().Intersect(dt2.AsEnumerable(),System.Data.DataRowComparer.Default)
if (dataRow.ToList.Count > 0) then copy to result datatable
Anil_G
(Anil Gorthi)
August 11, 2023, 2:26pm
7
@A_Learner
Is the dt1 and dt2 having data?
Cheers
Yes, thank you. I am reading from Excel files. Both data tables have data.
Anil_G
(Anil Gorthi)
August 11, 2023, 2:33pm
9
@A_Learner
Can you please check if there is a duplicate datatable with same name and different scope
Cheers
Yes, this is the reason. Thanks @Anil_G
Thank you, @supermanPunch
1 Like
system
(system)
Closed
August 14, 2023, 2:42pm
11
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.