Issue filtering when the source can contain no DataRows

I’m reading from a datatable and attempting to filter out various results.

The first file is produced by reading a datatable & filtering where the Status column is populated. This works fine.

The issue is the second file - I’d like to produce a file where the status column is empty (the rest of the columns can be populated). This file can have 0 rows or many.

I do this at the moment by assigning dt2 = dt1.Select(“[Status]=‘’”) then passing that to an output file. When the results offer one or more rows it works fine. When the file is empty, I receive the error 'The source contains no DataRows '.

I’ve tried to use an ‘if’ statement dt2.Rows.count() > 1 then either writing to a file or stepping over. I can only do this after the Assign has taken place. But the Assign is where the error seems to be thrown…

@qwerty1
Once after you filter the datatable
check the datarow array count >0
if it’s greater than zero then convert to datatable.

for example
Let us create drabc datarow array

drabc=dt1.Select(“[Status]=”“”)

then check drabc.Count>0

if its gretaer than zero then convert to datatable by using

dt2=drabc.CopyToDataTable()

Regards,
Mahesh

2 Likes

Hi @qwerty1,

before assigning data table check if condition
dt1.Select("[Status]=''").length>0
if return true do the process else skip

Regards,
Arivu

2 Likes

Thank you - that works perfectly.
Is there a way that I can use an and in here

i’ve tried dt1.Select(“[Status]=‘’” and [Age]<=30).length>0 but it seems to disregard the second condition.

Hi @qwerty1,

yes you can use use below code
dt1.Select("[Status]='' and [Age]<=30").length>0

Regards,
Arivu