Checking Arrays values in datatable

Hi UiPath,

Let say I have the array below:

arrString = {“Contract”,“YR”,“Year”}

and I have a datatable variable dtTable

Table below:

Short Text
ARUBA 3Y FC NBD EXCH 4100I 12G SVC
ARUBA 3Y FC NBD EXCH 4100I 24G SVC [FOR
Aruba 4100i 12G CL4/6 POE 2SFP+ DIN Sw
ARUBA 4100I 24G CL4/6 POE 4SFP+ SW

My goal is to check if atleast one values in the array exist on the datatable.

hope my requirement make sense.

Thanks in advance

@alvin.c.apostol26

arrstring

dt=dt.AsEnumerable.Where(function(r) arrstring.Contains(r(“ColumnName”).ToString)).CopyToDataTable

check this

You can try this link it will give as output Boolean ,if any row in data table consists that it will give true orelse false

dt.AsEnumerable().Any(Function(row) arrString.Any(Function(str) row(0).ToString() = str))

let me know is this your expected output ?

@alvin.c.apostol26

Follow this steps for output

note : arrSstring Variable Type = System.String[]
outPut Variable Type = System.Boolean

@alvin.c.apostol26

@alvin.c.apostol26

if you want any other let me know

cheers

Query 1 - Check if at least one value from the array exists in the DataTable (returns a boolean):

Boolexists = arrayOfValues.Any(Function(value) dt.AsEnumerable().Any(Function(row) row.ItemArray.Any(Function(field) field.ToString() = value)))

Query 2 - Filter DataTable to include rows where the array value exists:

 dt = dt.AsEnumerable().Where(Function(row) arrayOfValues.Any(Function(value) row.ItemArray.Any(Function(field) field.ToString() = value))).CopyToDataTable()

Hope this helps

Cheers @alvin.c.apostol26

1 Like

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