Hi All,
I need one linq query for the below situation
There is value stored in variable Val
The datatabe variable is dt
I have to search in column Name “Name” in datatable dt if that value contains
Hi All,
I need one linq query for the below situation
There is value stored in variable Val
The datatabe variable is dt
I have to search in column Name “Name” in datatable dt if that value contains
Use the below LinQ Expression to check the variable value contains in the column or not, it gives the boolean value true or false,
- Assign -> ValuePresent = dt.AsEnumerable().Any(Function(row) row.Field(Of String)("Name").Contains(Val))
Note : ValuePresent is the boolean datatype variable.
Use the below LinQ Expression to store the rows in a column which contains the Variable value, output is store the matched rows in a output datatable,
- Assign -> Output_dt = dt.AsEnumerable().Where(Function(row) row.Field(Of String)("Name").Contains(Val)).CopyToDataTable()
Note : The Output_dt is the datatable variable
Hope it helps!!
Hi,
Can you share expected result? If you need to filter datatable, the following will work.
dt.AsEnumerable.Where(Function(r) r("Name").ToString.Contains(Val)).CopyToDataTable()
Regards,
foundRows = dt.AsEnumerable().Where(Function(row) row.Field(Of String)("Name").Contains(Val)).ToArray()
Why do you need a linq for this…
You can directly use filter datatable woth contains
Cheers
@Ritaman_Baral
Assign activity:
resultRows = dt.AsEnumerable().Where(Function(row) row.Field(Of String)(“Name”).Contains(Val)).CopyToDataTable()
@Ritaman_Baral (From row In dt_2 Where row("Name").tostring.Contains(Val) Select row).CopyToDataTable()
I want to reverse the condition.
I need to check if var contains in each row “name”
anything is same @Ritaman_Baral
- Assign -> Output_dt = dt.AsEnumerable().Where(Function(row) Val.Contains(row.Field(Of String)("Name"))).CopyToDataTable()
Check the above one.
Hope you understand!!
If NO rows filtered it throws error. So, First Check it by below expression.
It’ll return TRUE or False (Use in IF Condition)
DT.AsEnumerable.Any(Function(x) x.Field(Of String(“Name”).Contains(Val))
Then Try below expression in Assign Activity
DT.AsEnumerable.Where(Function(x) x.Field(Of String(“Name”).Contains(Val)).CopyToDataTable
Hope it will helps you ![]()
Cheers!!
you mean you need to get all the rows which contains var in the column name Name?
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.