Values match of two column of data table

Dear Forum Members,

I have a scenario where i have two data table dt1 and dt2. In dt1 there are two columns A and B and in dt2 there is a column c. So i want to match the column C value of dt2 in the column A of dt1. And which values are match from C to A then in dt1 there should be “Yes” in B column of dt1. And which value’s are not matched there should be “No” in Colum B.

Please suggest me any Linq query.

Thanks in advance.

Hi, please try this query:

(From d In dt1.AsEnumerable
Let a = If(dt2.AsEnumerable().Select(Function(r) r("C").ToString).Any(Function(x) x = d("A").ToString), "Yes", "No")
Let ra = d.ItemArray.Take(d.ItemArray.Length-1).Append(a).toArray 
Select dt_result.Rows.Add(ra)).CopyToDataTable

It should work although I am sure there are faster solutions.

This checks string values, please edit if you need a different data type.

1 Like

@nespalvota Thanks for the Reply.

But what is dt_result data table. I have Created a data table variable named as dt_result and assign whole query result into it, but it’s showing an error like, Assign: Object reference not set to an instance of an object.

Thanks

dt_result is the resulting datatable.

You can use Assign activity to initialize the new datatable:
dt_result = dt1.Clone

You can also check test .xaml file attached:
DataTables.xaml (10.3 KB)

Hi @Yankit_Singh_R
Another way to try is using invoke code

Invoke code arguments:
Argument------Direction--------------Value
dt1 ------------ In/Out ----------------- dt1

dt2------------In/Out------------------- dt2

Now use the below code in invoke code

dt1.AsEnumerable().ToList().ForEach(Sub(r) r("B") =If(dt2.Asenumerable().Where(Function(row) row("C").ToString.Equals(r("A").ToString)).Count<>0,"Yes","No"))

Regards,

Nived N

1 Like

@nespalvota

Thanks, It helps me a lot.

@NIVED_NAMBIAR

Thanks For the reply.

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