LINQ - Filtering out empty rows

Hello Friends,
I want to display non empty/non null rows based on column “country”.
I am getting error as shown in below screenshot,

LINQ :–>

(
From currentRow In DataTbl
Where Not currentRow(“Country”).ToString.IsNullOrEmpty
Select currentRow
).CopyToDatatable

May i know why i am getting this error? and how to resolve this error?

1 Like

(From d In DataTbl.AsEnumerable
Let chk isNothing(d(“Country”)) OrElse String.IsNullOrEmpty(d(“Country”).toString.Trim)
Where Not chk
Select r = d).CopyToDatatable

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

Also have a look here:
[HowTo] LINQ (VB.Net) Learning Catalogue - Help / Something Else - UiPath Community Forum

Hi @Neal369

Try this

(
From currentRow In DataTbl.AsEnumerable
Where Not String.IsNullOrEmpty(currentRow(“Country”).ToString)
Select currentRow
).CopyToDatatable

Hope this helps

2 Likes

@Neal369

Alternate Approach:

dt.AsEnumerable.SkipWhile(Function(row) String.IsNullorEmpty(row(“country”).ToString)).CopyToDataTable

Hope this helps,
Best Regards.

1 Like

We keep in Mind:

Col Value Sequence: A, B,C, NullOrEmptyString, E, F
SkipWhile will stop after C and not return E,F

1 Like

This is not working,
Giving below error -

@Neal369

I believe you copied the formula directly and pasted it…the error is becUse of the inverted comma…please remove it and re add it…that would solve the error

Cheers

1 Like

Always ensure or retype all Double Quotes as it has to be: " sometimes copy paste will cause this issue

1 Like

@Suraj_B_Shetty

This works perfect, thank you :slight_smile:

1 Like

Correct, my apologies, thank you

1 Like

Working perfect,
Thank you :slight_smile:

1 Like

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