Matching an array and data table

Hi everyone,

I have an array and data table consists of dates. I want to check if the dates that are in the data table match with the array. Then, it prints “arrayDate=Tabledate” therefore, it matches. Else, it prints the dates do not match

getting the datatable column value into an array we can do

arrDataDates =

YourDataTableVar.AsEnumerable.Select(Function (x) x(YourColNameOrIndex).toString.Trim).toArray

so with the in your other topic mentioned Set Operation options we can check for the present/absent values

when implementing your case within a for each row we can do:
For each row in datatable

  • IF: arrDate.Contains(row(YourColNameOrIndex).toString.Trim)
    • then: do actions for the matcher
    • else: do actions for the non matchers

grafik

I am using Dt.AsEnumerable.Select(Function (x) x(Dt.Rows(“Date”).toString.Trim).toArray). However, I am getting implicit conversions from string to integer error

1 Like

Hey @RPA_Path

Kindly try the below,

Foreach Row in DataTable

   If dateArr.Contains(Row("Date").ToString.Trim)

         Print "Match"

   Else 

         Print "No Match"

Hope this helps.

Thanks
#nK

@RPA_Path

Above expression is wrong. It should be like below.

Dt.AsEnumerable.Select(Function (x) x("Date").toString.Trim).toArray

@RPA_Path

Here you are trying to loop one by one item from DataTable and checking against the array. If the value match then it will go to the Then part else Else part.

1 Like

I see where it went wrong, thank you.

1 Like

One more question, is it possible to log the dates that were matched instead of the word “match”?

@RPA_Path

Yes you can. Write below expression in Log Message activity.

         row("Date").ToString.Trim
1 Like

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