Assign - the source contains no data row - problem with extracting data from empty datatable

Hello. I have problem with assign activity. I have two datatables, which I compare to each other. I don’t have rows in any of them process i returning message “Assign - the source contains no data row - problem with extracting data from empty datatable”.

Regular situation is that I don’t have to have data every time, but don’t know how to force assign activity to get empty datatable.

Before that you need to Check the count of rows
for this
Count=DT.Asenumerable.Count(Function(r) conditionPart)

if Count>0
Then
Next Step

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

Why is it returning me this error when I’m trying to use what you suggested

Put this linq in the if activity and replace the CopyToDatatable with Any method and if it’s going to then block it means the linq is satified and you can put you assign activity in else block you can do whatever you want.

This way you can prevent this error.

I don’t understand. Could you, please, write down example that is based on my question?

Use an If to check that there is data in both datatables.

Hey @Olivera_Kalinic,

Do it like this for both the datatables.

Thanks,
Sanjit

That causes the LINQ query to be processed twice. Just do dt.Rows.Count >0 in the If condition to make sure it has data.

1 Like

Ok, but in case I get no data, is it possible to write down some “0” values in destination excel files?

@Olivera_Kalinic
you got several inputs including the firstAid sheet which is guiding you to rewrite the CopyToDataTable into a toList and evaluating based on the count if CopyToDataTable or Clone is to execute.

Regarding to your LINQ a String.IsNullOrEmpty(yourString.Trim()) would handle more strict and greedy the blank check

Does this not solve your case?

Please, could you be more specific? :).
I didn’ understand anything :slight_smile:

did you read?
🚑 🆘 [FirstAid] Handling of The source contains no DataRows exception?

what is unclear after reading?

Of course. Just do those steps in the Else block of the If.

When trying to do those steps, I’m getting the error bellow

What is strCCFilter?

When I’m trying to assign list of data rows to resultP variable, getting this error:

What trying is to create list of Data Rows from dt1Upareni.AsEnumerable.Where(Function(x)Not (String.IsNullOrEmpty(x(“Uparivanje”).ToString) or String.IsNullOrWhiteSpace(x(“Uparivanje”).ToString))).CopyToDataTable

in the tutorial the steps are explained at an example and can be applied to the individual case. For sure it is not about replacing the own statement with the tutorial code.

sure done in this way it will not work
grafik


As mentioned in the tutorial


then

then
grafik
we changed copytodatatable to ToList and assigned it to variable Result

finaly we check the Count of the Result (which is a list of datarows) and use Copytodatatable or cloning the origin datatable

1 Like

Does anyone haave opinion about this post?

Hi @Olivera_Kalinic ,

Can you try the below in IF condition

YourDatatable.AsEnumerable.ANY(Function(x) X(“DtColumnName”).Contains(String) Or any candition you want to validate against column)

Sample : dtSample.AsEnumerable.any(Function(x) x(“Code”).Tostring.Contains(“FR”))

The above expression will result in a Boolean.

If the condition is true , then use the expression in the snapshot provided by you
If the condition is false, Then you can clone the datatable which will give you an empty data table.

Hope This Helps !