Remove particular rows using LINQ

This is my dummy datatable

I want to write a linq query to remove particular row
If row is kolkata then remove it

How can i do it using below code
(From row In dt_A
If(row(“City”).Equals(“Kolkata”))
Then

).CopyToDatatable

in general we would use a filtering with the where operator

dtFiltered =

(From row In dt_A.AsEnumerable()
let v = row("City").ToString.ToUpper.Trim
Where Not v.Equals("KOLKATA")
Select r = row).CopyToDatatable

Handling empty result we do:

Also have a look here

1 Like

Hi @Kira

DT.AsEnumerable.Where(Function(r) r.ItemArray.Any(Function(x) Not x.ToString.Equals(“kolkata”))).copytodatatable

@Kira

dt.AsEnumerable.Where(Function(row) Not row(0).ToString.equals(“Kolkata”) ).CopyToDataTable

i Have shared the image

Hope this helps

Hey @Kira

You can use below code

(From row In YourDT
 Where Not row("City").toString.ToUpper.Trim.Equals("KOLKATA")
 Select row
	 ).CopyToDatatable

Try this and let us know the output

Hope it helps you out

1 Like

How can i achieve it using skip?

(From row In dt_A
Where row(“City”).toString.ToUpper.Trim.Equals(“KOLKATA”)
Skip row
).CopyToDatatable

I tried this but didnt work

Also Thank you @ppr and @Vikas_M

what was done in detail, show us the modeling and the input data

dt = (From row In dt_A.AsEnumerable()
Let city = row(“City”).ToString.ToUpper.Trim
Where Not city.Equals(“KOLKATA”)
Select r = row).CopyToDataTable()

that includes all rows except those where the

City column has the value KOLKATA.

Hope it may help you

Cheers @Kira

Why don’t you just use the Filter Data Table activity? Simple, easy, quick…you’d have it working already.

@postwick , @ppr , @Vikas_M , @Shiva_Nikhil , @Dinesh_Guptil , @Praveen_Mudhiraj ,

Which one is better ,
Linq or Activities
I know that these kind of tasks can be done using activities, But i wanted to know why LInq then?
According to me, i feel like Linq is Better than activities
Please enlighten me with your knowledge

1 Like

Activities are much simpler and easier and faster.

Only use LINQ when you need to because an activity can’t do what you want.

Linq is not better than activities.

Ohh thanks for the clarification @postwick

On first it depends on the mutually agreed skill sets of the development team, and how / if LINQ is allowed

when there is no need to touch the left side (e.g. toupper, trim) then Filter DataTable can be used

When there is a need to touch the left side (eg toupper, trim) then a data cleansing is needed or can be done directly within the LINQ (we have seen abover, toupper, trim).

So it depends on other factors, when to use LINQ or not

2 Likes

Th thread is getting distracted to another topic, so am going to clos this thread here

Thank you everyone for enlightning me

the choice depends on the specific task you are trying to do… If it is not possible to activities better you can go for the linq

Ohh thank you so much @ppr

project.json (1.5 KB)
Remove particular rows using LINQ.xaml (10.5 KB)

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