Getting error: The given key was not present in the dictionary

Hi @ppr & @kumar.varun2

I’m getting error as the key is not present in the dictionary.

The datatable is same

@riyatona18 Its means your value is not present in dictionary, usually it is coming from Config file reading. are you using another dictionary?

Yes I’m. Please refer above thread.

Hi @riyatona18

Try with this

LINQ_ComarisonTwoDataTables.xaml (7.6 KB)

and provide the feedback

There’s no error for this xaml. I wonder what’s the mistake.

1 Like

@riyatona18

The keys of dictionary are string.
Without string manipulation - "Robot", "ROBOT", " Robot " will be different keys
So, I have added string manipulation for the dictionary key. (ToString.Trim.ToUpper)
Removing the space at the start and end of the string
Making the characters of the string Uppercase

I’ve added trim and toUpper even then the error is same

The above issue got solved. Although the linq removes the roles which are not present in the second DT
For example:

DT1
Robot
Developer

DT2
Robot
Developer
Manager

Output:
Robot
Developer

Expected Output is different:
Output
Robot
Developer
Manager

Can you please help me with this?
@ppr @kumar.varun2

Hi @riyatona18

Please provide the sample input and output

PFB input and output:

DT1

Role A B C D E F G H I
Administrator Y Y Y N Y Y Y
Robot N Y N N Y Y Y
Developer Y

DT2

Role A B C D E F G H I
Administrator Y Y Y N Y Y Y Y
Robot N N Y N Y Y Y
Developer N N
Manager Y

Output:

Role A B C D E F G H I
Administrator Y Y Y N Y Y Y_Change Y
Robot N N_Change Y_Change N Y Y Y
Developer N_Change N_Change
Manager Y

Output will contain roles which are missing in DT1 but is available in DT2.

@riyatona18

what would be the output if the inputs are like below

DT1

Role A B C D E F G H I
Administrator Y Y Y N Y Y Y
Robot N Y N N Y Y Y
Developer Y

DT2

Role A B C D E F G H I
Administrator Y Y Y N Y Y Y Y
Developer N N
Manager Y

As I’m adding this data to excel file. It should add a comment.

For example:

DT1

Role A B C D E F G H I
Administrator Y Y Y N Y Y Y
Robot N Y N N Y Y Y
Developer Y

DT2

Role A B C D E F G H I
Administrator Y Y Y N Y Y Y Y
Developer N N
Manager Y

Output would be:

Role A B C D E F G H I
Administrator Y Y Y N Y Y Y Y
Developer N N
Manager Y
Role removed: Robot(last row of the file as a footer)

If any new role is added then role would be added and that particular cell would be highlighted in green.

But in this case, it is excluding the new roles and adding just the ones which are present in the DT1.

The comment part is taken care of. But then all roles should be added.
The ones which are matching should be compared and new ones to be added as is.

Hi @riyatona18

Try with this xaml

LINQ_ComarisonTwoDataTables_2.xaml (7.6 KB)