How to handle the no data row exception in try catch

What is the type we need to select in the try catch when No data result came.

example: We have a data table and I filtered the data table using LINQ.
after filter we will get 0 rows that time we will get an error in assign activity.

How to handle that in try catch

Hi,

I suggest you to surround Trycatch around the Assign activity which you given LINQ condition. In catch block you can mention System.Exceptions to catch the Generic exception and log it if you want to.

image

Hi copy_writes,
Please try to check the condition before using an If activity. i.e. you can use this demo condition to validate if your dt after apply the filter contains data rows:

yourDataTable.AsEnumerable.Any(Function (x) x("Column1").toString.Trim.ToUpper.Equals("AnyValue"))

Cheers

Hi @copy_writes

You can use this in If

IsNothing(dt) OrElse dt.AsEnumerable.All(function(x) x.ItemArray.All(function(y) String.IsNullOrEmpty(y.ToString)))

Regards

Hello, it would be easier if you share withs which can of filter you apply with linq.
For instance if you use First() or Single(), you need to be sure that you will get at least one for First() and only one for Single() instead use FirstOrDefault, SingleOrDefault…
Also to check if a collection is empty please use

apples.Count= 0

Hope that helps

Hi Team,
@vrdabberu @jose.ordonez1 @Uthraa_S

I am filter the data table Like where the Text is contain Sorted.

I use: dt.asenurable.where(Function(r) r(“text”).tostring.tolower.trim=“sorted”).copytodatatable()

Hi @copy_writes

You can use Any Function in IF Condition first. It’ll return True and False

dt.asenurable.Any(Function(r) r("Text").tostring.tolower.trim="sorted")


OR use this in Assign Activity


IF(dt.asenurable.where(Function(r) r("Text").tostring.tolower.trim="sorted").ToArray.Count>0,dt.asenurable.where(Function(r) r("Text").tostring.tolower.trim="sorted").copytodatatable,dt.clone

Hope it will helps you :slight_smile:
Cheers!!

Hi @copy_writes

Try this in Assign acitivity:

FilteredRows = If(dt.AsEnumerable().Any(Function(row) row("text").ToString().ToLower().Trim().Contains("sorted")), dt.AsEnumerable().Where(Function(row) row("text").ToString().ToLower().Trim().Contains("sorted")).CopyToDataTable(), New DataTable())

FilteredRows is of DataType System.Data.DataTable

Regards

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