Hi,
I was trying to compare two excel with LINQ Intersect but keep getting error message “Assing: the soruce contains no Data Rows”.
That error occurs when the LINQ query doesn’t return any matching rows, and CopyToDataTable()
fails because it requires at least one row to create a DataTable
. You can fix this by checking if the result contains any rows before calling.
You can handle this properly using this logic:
Declare a variable of type IEnumerable(Of DataRow)
for example in assign activity
result = DT1.AsEnumerable().Intersect(DT2.AsEnumerable(), System.Data.DataRowComparer.Default)
Now using If activity check if there are any items in the result
like this
If result.Any() Then
finalTable = result.CopyToDataTable()
Else
finalTable = DT1.Clone() ' Creates an empty DataTable with the same schema
End If
Will try doing it. Thank you
Looks like there are no common rows in intersect and hence the error..generally while using copytodatatable we need to to be cautious to first check if any rows are present
If(DT1.AsEnumerable.Intersect(DT2.AsEnumerable, System.Data.DataRowComparer.Default).Count >0, DT1.AsEnumerable.Intersect(DT2.AsEnumerable, System.Data.DataRowComparer.Default).CopyToDataTable,Dt1.Clone)
Cheers
I understand that the Bot would Fail here once the error Occurs. If you wish to continue ahead if there are no rows filtered with the LINQ query, Simply surround the assign activity (having the LINQ filter) with a try catch . Configure the Exception section as per your need. The workflow will continue in case of no rows filtered.
Thank you guys. Sorry, not sure how I missed these reply’s.
Please mark the answer as Solution if it worked for you bro Cheers!!