Correct this code

dt3.AsEnumerable.where(Function(x)dt_TR.AsEnumerable.Where(Function(y)x(“col1”).ToString.Contains(y(“Col2”).ToString)).Count>0).CopyToDataTable

i have this code and i want to match all values of Col1 and Col2 values.

Col1 column value is like abc and Col2 column value like le_abc
please correct this code.

@Luffy
Try this one

dt3.AsEnumerable().Where(Function(x) dt_TR.AsEnumerable().Any(Function(y) y("Col2").ToString().Contains(x("Col1").ToString()))).CopyToDataTable()

1 Like

Hi @Luffy

dt3.AsEnumerable().Where(Function(x) dt_TR.AsEnumerable().Any(Function(y) x(“Col1”).ToString().Contains(y(“Col2”).ToString()))).CopyToDataTable()

Hope it helps!!

1 Like

i have already implemented this solution but not getting the correct output.
only 1 matched row will generate.

@Luffy
Try this with to upper

dt3.AsEnumerable().Where(Function(x) dt_TR.AsEnumerable().Any(Function(y) y("Col2").ToString().ToUpper.Contains(x("Col1").ToString().ToUpper))).CopyToDataTable()

Hi @Luffy

Try this:
dt3.AsEnumerable.Where(Function(x) dt_TR.AsEnumerable.Any(Function(y) x("Col1").ToString.Contains("le_" + y("Col2").ToString))).CopyToDataTable()

Hi @Luffy

Try this

dt3.AsEnumerable().Where(Function(x) dt_TR.AsEnumerable().Any(Function(y) y("Col2").ToString().Contains(x("Col1").ToString()))).CopyToDataTable()

I hope it works!!

getting same 1 row value

not working , only 1 row is coming

@Luffy How many rows should come after matching. If its giving one row it means that something different in data

@Luffy

Try this once

dt3.AsEnumerable().Where(Function(x) dt_TR.AsEnumerable().Any(Function(y) y.Field(Of String)(“Col2”).Contains(x.Field(Of String)(“Col1”)))).CopyToDataTable()

output should be 5 rows and here we are just matching one column don’t know what i am doing wrong

Better paste here your sample data and the expected result.

Cheers

Hi @Luffy

Could you please share what you are linq querey and workflow. Then we will get better understanding about it.

Hope it helps!!

@Luffy

Use this :
dt3.AsEnumerable.Where(Function(x) dt_TR.AsEnumerable.Any(Function(y) x("Col1").ToString.Trim().Contains(y("Col2").ToString.Trim(), StringComparison.OrdinalIgnoreCase))).CopyToDataTable()

or in LINQ form

dt = (From a In dt1.AsEnumerable
Where dt2.AsEnumerable.Any(Function (b) CStr(b(“col1”)).Contains(CStr(a(“col1”))))
Select r=a).CopyToDataTable

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