Hey everybody! I’m having a little trouble here. Basically, I am trying to assign to check if email is already exist or not before copying the datatable. I created 2 Datatable: Result_DT contain null and Master_DT contain the Email. I have this error while I was debug and it says Error: Source contains no datarows.
I write the expression in the Assign Activity - Master_DT.AsEnumerable().Where(Function(row) row(“Email”).ToString=item(“Email”).ToString).CopyToDataTable()
I am trying to cater for exception where there is no record retrieve from the Excel file but to no avail.
Whether Master_DT contains any data in it? @mosyahri
Master_DT has data inside.
@mosyahri, So before assigning Master_DT to Result_DT, add a assign activity with Result_DT = Master_DT.Clone
And your condition should be changed in if conditon, it should be Master_DT.Rows.Count > 0.
Does not work. Still the same results.
The correct way to check if rows exists in a datatable: How to check if datatable has no row - Build - UiPath Community Forum
Solution from @Palaniyappan:
dt.Rows.Count = 0 OR dt.Rows.Count>=1
- Then use Clone to get properties of
Master_DT (Clone is only a clone no rows will be found when you clone. It only copies the column types and names to the assigned datatable)
- Followed by your second Assign
Still shows the same error
I see you have not changed the if condition at all.
In your case:
Master_DT.Rows.Count = 0 OR Master_DT.Rows.Count>=1
I just modify the IF condition but still show the same error.
I suggest you check what the output of your linq query is. I think you are missing adding rows in your linq query.
You can try to specify how many rows you want to copy to the Result_DT as well. My know how of linq query is rudimentary. I use
@mosyahri, Can you check the count of Master_DT.AsEnumerable().Where(Function(row) row(“Email”).ToString=item(“Email”).ToString).ToArray.Count > 0 before assigning to Result_DT.
similar to the example below an empty result can be handled defensively:
Hello Peter, I have a query on the same topic. There’s a select query being used for my datatable and the error I am getting is that the "datatable has no datarows. "
the query I am using to solve this is::: dt_TransactionHistory.Select("[TransactionDescription]=‘Coverage Change’ OR [TransactionDescription]=‘Terminate Coverage’ ").CopyToDataTable.Rows.Count=0
however this is not able to resolve the issue as I get the same error.
What could be done in this case?
looks like this typical message: The source contains no DataRows.
apply the pattern from above:
dt_TransactionHistory.Select("[TransactionDescription]=‘Coverage Change’ OR [TransactionDescription]=‘Terminate Coverage’ ").toList
Hi Peter thanks for responding quickly. The mistake that I was doing was that I was including copytodatatable() method at the end. It is redundant while taking count post filteration in case there are no data captured using the query.
I tried using your query , it worked as well.