How to use "IN" Operator in where clause

Hi Team,

I am trying use “IN” Operator in where clause , getting an error like “)” expected.
Please help me on this…

I have been using the syntax like…
dt1=(From p In dt1.Select Where p(“Name”).tostring In(a) Select p).copytodatatable

Thanks in advance.

Hey,

can you elaborate on what you are trying to do here, which rows you want to copy.

Please try like this
Dt1.Select(“Name = ‘’(Name here)”).CopyToDatatable

I want to select particular rows using IN Operator in where clause
Like in a datatable if there are A,B, C Values in the column ,i want to select A, B rows

@prathima,

Try with this query,

From r as DataRow in dt1.Rows Where lstNames.contains(r.Item(“Name”)) Select r

Here you need to have a List(of String) type variable named as lstNames with the values you want to filter. This will result as a IEnumerable Collection of DataRows

Hi Sarathi,

I am getting an error as in below screenshot…

Thanks,

This is working for me, please check this

(From r In dtOut.AsEnumerable() Where lstNames.Contains(r.Field(Of String)(“Name”)) Select r).CopyToDataTable

and assign this to a datatable in an assign activity

Thank you it is working…

Before assign it to a datatable, check that using a IF with this condition.

(From r In dtOut.AsEnumerable() Where lstNames.Contains(r.Field(Of String)(“Name”)) Select r).Count > 0

This will avoid error if there is no row with the matching scenario.

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