Match string variables with Data table

Table stored in Data table for validation (attached file for your DT reference)
comm_purch.xlsx (9.8 KB)

Note: Each value separated by comma in 2 columns in DT (Refer screenshot below)

Example values store in variable:

Str_Commodity = “D” or “E” or M

Str_PurgOrg = “0002” or “HCGA” or “IADM”

Requirement:

Need to match 2 string variables values with any one of the value (separated by comma) both 2 columns in Data table.

Expected output:

When Str_Commodity = “D” and Str_PurgOrg = “0002” then expected output in str_status variable is “Yes”

When Str_Commodity = “D” and Str_PurgOrg = “HCHK” then expected output in str_status variable is “No”

Assign Activity:
hasFound | Boolean

(From d in dtData.AsEnumerable
Where d("Commodity").ToString.Trim.Split(","c).Any(Function (c1) c1.Trim.Equals( Str_Commodity))
Where d("PurchOrg").ToString.Trim.Split(","c).Any(Function (c2) c2.Trim.Equals( Str_PurgOrg))
Select r=d).Any()

UPD1 -
However kindly note:
grafik

there would be a match or you should organize the checks different

@Sathish_Kumar_S

Try this

dt.AsEnumerable.Any(function(x) x("Commodity").ToString.Split(","c).Any(function(y) y.Trim.Equals(str_commodity)) AndAlso x("org").ToString.Split(","c).Any(function(y) y.Trim.Equals(str_purgorg)))

This gives true if atleast one row matches else it wont

Cheers

1 Like

Sorry i made a mistake in the logic…

*When Str_Commodity = “D” and Str_PurgOrg = “HCHK” then expected output in str_status variable is Should be "YES

*When Str_Commodity = “D” and Str_PurgOrg = “PIND” then expected output in str_status variable is Should be “No”

then go ahead with the given approaches. Kindly note that we handled the return as Boolean as this is the appproproate Datatype for a check

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