How to prevent a fault due to null value in an assign activity using dt.Select to filter?

Hello,

I have a sequence that sums a data table column after filtering it based on values in two of its columns. This sequence works fine when there’s a value after the filter, but I also need it to work if there’s no value.

How do I get this to work?

My code is below (assign #1 is where the fault happens when there’s no value based on the filter)

Assign #1 (Filtering Data Table):

dt2 = dt1.Select("[Column 1] in (‘abc’) and [Column 2] in (‘xyz’) ").CopyToDataTable

Assign #2 (Summing Column from filtered DT):

dt3 = dt2.AsEnumerable.Sum(Function (x) If(Double.TryParse(x.item(“Column 3”).ToString, Nothing), Double.Parse(x.Item(“Column 3”).ToString), 0))

Hi,

dt2 = dt1.Select("[Column 1] in (‘abc’) and [Column 2] in (‘xyz’) ").CopyToDataTable

Perhaps, first you should get the result of “Select” as Array of DataRow.
Then check its length, like the following.

arrDataRow = dt1.Select("[Column 1] in (‘abc’) and [Column 2] in (‘xyz’) ")
if arrDataRow.Length=0
then dt2 =dt1.Clone()
else dt2=arrDataRow.CopyToDataTable()

Regards,

3 Likes

Thanks!

1 Like

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