Error: "The Source contains no DataRows" with If Condition: "Datatable.Select("[column1]=’”+row(0).ToString"'").CopyToDataTable is Nothing OrElse Datatable.Select("[column1]=’”+row(0).ToString"'").CopyToDataTable.Rows.Count=0"

I would like to know if there is a way to avoid error and continue the flow in the below situatioin.

I have dtA(row1) and dtB(row2).
Using For Each Row, I want to create another datatable (dtC) which contains data
that dtB doesn’t have but dtA has.

1.First I placed “For Each Row” Activity.

ForEach “row1” in “dtA.Select().CopyToDataTable.Defaultview.ToTable(True,“column1”)”

  1. In the for each activity, I placed “If” Activity.

is Nothing OrElse

3.When I ran the xaml I get the error: “The Source contains no DataRows.” and it stops the flow.
I want to make it continue the flow in the situation with no DataRow.

Thank you very much for reading the question.
I’m sorry I am not able to explain better.


Place that expression inside Try block and if source does not contain any rows then it will go to Catch block to catch that exception and it will continue with other activities without stopping the flow.


CopyToDataTable method returns exception if the result of Select metod(Array of datarow) has no item.
So perhaps you should check the result of Select method before use CopyToDataTable as the following image.



1 Like

Thank you for your quick and useful reply! I tried it and it worked. Only because I had to nest this kind of structure multiple times I decided to find another way this time. Thank you very much again.

1 Like

I appreciate you very much for your quick and detailed advice. Following your xaml capture I could achieve what I wanted.
If I may ask further, would it be working when writing the If condition: arrDr.Length=0 ?
I heard computer is faster when processing “=” conditions than “<>” condition, because when processing “<>” condition it has to look up every pattern to judge the condition.
When I tried on my xaml it seemed fine, but I would like to know if there’s reason to write with “<>”.
Thank you very much and I’m sorry to take your time.


When I tried on my xaml it seemed fine, but I would like to know if there’s reason to write with “<>”.

In this case, I put emphasis on readability as the normal case in “Then”, non-normal case in “Else”.
And probably there is no difference for processing speed. If “<>” would become “=”, it just exchange between “Then” and “Else”


Thank you very much for kindly replying. Your advice helped me a lot.

1 Like

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