How to find whether a value from datable is present in dictionary key set and add that the corresponding row from datatable to a list which is of type datarow

Can someone help me to check if the value say “item”(this belongs to a particular name column in a datatable) is present in a dictionary(name, email).
If it belongs , then i have to extract that particular row and add to a newly created list which is of type datarow

Kindly help

Hello @shilpa_p ,

You can use this in the if condition inside for each row to check if value is present in your dictionary:
Dict.Keys.Contains( CurrentRow(“Name”).ToString)

If it contains, you can add the row to your list/array using “Add To Collection” activity.


Thanks Athira
I shall try this

1 Like

Sure! Please try and let me know :slight_smile:

Hi @shilpa_p ,

Let’s say we have the following the variables :

DT as a Datatable variable, item as a String, dictVar as a Dictionary, dataRowList as List of DataRow.

  1. Checking the Item is Present in the Dictionary. Assuming that we are Checking the name, which is the Key in Dictionary we can do the following by Specifying the condition below in an If Activity:

if the Check is for the Values, we can use the below Expression :

  1. In the Then Part, we can get the Matching DataRow from Datatable using an Assign Activity in the below way :
arrayRow = DT.AsEnumerable.Where(Function(x)x("Name").ToString.Trim.Equals(item.ToString.Trim)).ToArray

where arrayRow is a variable of Type Array of DataRow

  1. Next, we can Check if arrayRow has any values using an If Activity with Condition in the below way :
  1. In the Then Part of If, we can Add the DataRow to the List of DataRows using an Invoke Method Activity.

Using a For Each to Loop through the Collection of Matched DataRows, add to the List of DataRows, Like Below :

Let us know if you are facing any difficulties while performing the above methods

Thank you so much.
I will try this as well. I guess it will work for me. I shall update you

1 Like

@shilpa_p , We would also need to make sure the dataRowList is initialised, Hence, We do the following at the beginning, or as a Default value for the variable :

dataRowList = new List(Of DataRow)

sure. I will do that

Thank you so much . It worked

1 Like

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