Compare Datatable values with array using linq

Hi,I have datatable ,and and array of string and i want to compare datatable value with array values,after compare need those data in a datatable using linq query?

Below is an example:

arrStr={“not required”,“no template required”}

dt_table

and the final output will be in datatable
Output:
dt_Final

Anyone help me writing linq query for the above scenario.Thank you

Hi @yashashwini2322

Use below query

DT = (From row In DT.AsEnumerable()
              Where arrStr.Contains(row("ColumnB").ToString)
              Select row).CopyToDataTable

Input:

The image shows an Excel spreadsheet with two columns labeled "ColumnA" and "ColumnB," containing various text entries such as "CS," "SM," "required," and "not required." (Captioned by AI)

Output:

Regards,

Hi,Thanks for the query help but,same linq query is not working for the below table.Any modification needed for query.

image

@yashashwini2322

I’ve changed the query, try this

DT = (From row In DT.AsEnumerable()
              Where arrStr.Any(Function(str) row("ColumnB").ToString.ToLower().Contains(str.ToLower()))
              Select row).CopyToDataTable()

Regards,

@yashashwini2322

Try this

DT = (From row In DT.AsEnumerable()
      Where arrStr.Any(Function(str) row("ColumnB").ToString().ToLower().Contains(str.ToLower()) AndAlso
                                   row("ColumnA").ToString().ToLower() = "cs"
      Select row).CopyToDataTable()

Regards,