Filter Table -> Source contains no data rows

When i’m filtering a Datatable, sometimes it wil give 0 data rows.
I’m Always getting an exception: The source contains no datarows.

That’s correct, but i don’t want this exception, when it has no datarows, i want a datatable that is empty, so when i do a row.count, it gives me 0

Is this possible?

Hi.

You can’t filter no rows to a Data Table, but you can use an Array of Rows. Unfortunately, it does not appear that the Filter activities let’s you store your table to an array.

The solutions to this would be either:

—placing your activity inside a Try/Catch, then when an error is thrown on it, use a Build Data Table with only headers in the Catch or just leave the Data Table as nothing (which can be checked in an If condition).

—use a vb net lambda or LINQ expression to filter the table into an array.

To be honest, I have never used the Filter Data Table activity.
But the solution for that would look something like this:

Try
    Filter Data Table
Catch
    Build empty Data Table

or
Try
    Filter Data Table
Catch
    <leave empty>

If activity //condition used: If( dtFiltered IsNot Nothing, dtFiltered.Rows.Count>0, False )

The coding method to filter (instead of the activity) would look like this:

Assign arrayVariable = dtSource.AsEnumerable.Where(Function(row) row("col1").ToString.Trim.ToUpper = "ABC" And If(IsNumeric(row("col2").ToString.Trim), CDbl(row("col2").ToString.Trim)<25, False) ).ToArray
If activity //condition: arrayVariable.Count>0


or
Assign arrayVariable = dtSource.AsEnumerable.Where(Function(row) row("col1").ToString.Trim.ToUpper = "ABC" And If(IsNumeric(row("col2").ToString.Trim), CDbl(row("col2").ToString.Trim)<25, False) ).ToArray
For each r In arrayVariable //to process each row in filtered array

EDIT: Also, you can always convert your filtered rows to a data table by using arrayVariable.CopyToDataTable, like inside the If condition that checks if .Count>0

Hope any of this is helpful.

Regards.