Linq help needed

ID First name Last name
1 Leela Johnson
2 Frankie Grande
3 Betsy Johnson
4 Jessie James
5 Peter Michaels

Using LINQ , get a new data table with only the rows where last name is “Johnson”.

Hi

Please use the below linq:

suppose your data is stored inside dt1 then :
Filtereddata= dt1.AsEnumerable().Where(function(x) x.item(“Last name”).toString.equals(“Johnson”)).copytoDataTable

where Filtereddata is DataTable type.

ID First name Last name
1 Leela Johnson
2 Frankie Grande
3 Betsy Johnson
4 Jessie FilteredJames
5 Peter Michaels

Using LINQ , get a new data table with only the rows where last name is “Johnson”.

Happy Automation
@S_S_Kumar

Hi @S_S_Kumar

You Can try with Filter data table Or Select Method

Using Filter Datatable

Column Name =“Last name” Equals Value =“Johnson”

Using Select method.

Dt.Select(“[Last name] =‘Johnson’”).CopyToDataTable

Then Write Range the Datatable

Regards

Hi
The below expression would help you resolve this issue

dt = dt.AsEnumerable().Where(Function(a) a.Field(of String)(“Last Name”).ToString.ToUpper.Contains(“JOHNSON”)).CopyToDatatable()

Cheers @S_S_Kumar

1 Like

thank you issue resolved.

1 Like

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