Error when I am trying to filters rows in data table using LINQ query when there is no value with search name

Hi Team,

I want to filter rows using LINQ query …

I have table like below

I want to filter only rows which is having “HSM” value in accounts column… I tried filter data table activity but it is taking too much time and failing sometime since I have lakhs of records in my excel.
So want to try using LINQ query and used below LINQ query shared by @J0ska @kumar.varun2 in another post .

dt_Data=dt_Data.AsEnumerable().Where(Function (row) row(“Accounts”).ToString.ToUpper.Trim.Equals(“HSM”)).CopyToDataTable

Dt.AsEnumerable.Where(Function(r) r.Item(“Accounts”).ToString.Equals(“HSM”)).CopyToDataTable

Above two LINQ queries is working when there is having “HSM” value in accounts column … But sometimes I am not getting “HSM” value in accounts column and BOT is failing in suck scenarios …

I want LINQ query which works in both the scenarios …

Scenario 1 : It Should return the rows which is having HSM value in accounts column when there is HSM value in accounts column
Scenario 2 : It Should return empty table when there is no HSM value in accounts column

@J0ska , @kumar.varun2 Could you please help me

Thanks,
Naresh

:ambulance: :sos: [FirstAid] Handling of The source contains no DataRows exception - News / Tutorials - UiPath Community Forum

we hope:

missing s in


was a typo

2 Likes

Hi @Mandava_Naresh ,

Is there any reason why you don’t want to use filter data table?

Said that, have you consider using the select method?
Note: it returns a DataRow[ ] not a data table

Dt.Select("Accounts = ""HSM""")

DataTable.Select Method (System.Data) | Microsoft Learn

Filter Data Table (uipath.com)