How to check LINQ have no datarows?

I have LINQ as below:
(From d In in_DataTable.AsEnumerable
Where d(“OU_NAME”).tostring.Trim.Equals(row(“OU”).ToString)
Let ex=d(“Log_File Name”).tostring.Trim().toUpper()
Where String.IsNullOrWhiteSpace(ex)
Select r=d).CopyToDataTable()
When there is no data, system exception and give Error message:
Assign: The source contains no DataRows.
How I check this place and don’t thrown the exception.

Hi @Lori

Before using the linq expression, Use an If condition to check the datatable contains any rows or not.

Take an If activity and give the below condition,

in_DataTable.rows.Count>0

In then block insert the assign activity which contains the linq expression.
In else block insert the assign activity to handle the exception.

Hope it helps!!

Hi,

I think it’s better to output result as DataRow array type, next check if it has datarow, then convert it to datatable, as the following.

Regards,

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