Error in linq when no datarows found

Hi Team,

I have written this code. It is working fine but it is throwing error when it does not contain any datarow.

How to solve this?

Hi @yash.choursia ,

Could you check the below post :

1 Like

Hello! Create an “IF” activity and the condition should be “Value that you want” = NULL
THEN:
ELSE: Add data row

Hope it helps! Cheers.

I think it’s the .CopyToDatatable that causes this error. What I did was create a list(of datatrow) variable and assign the linq expression to it without the .CopyToDatatable part. Then you can do an If activity with listVar.Count>0 as the condition. Inside the if, do your assign notvalidmaterial_DT = listVar.CopyToDatatable

If the issue is that the linq throws an error when the linq result is empty. Then convert the linq to array using .ToArray in end instead of .CopyToDataTable.

Then check if the array is null, if it is null - output datatable is empty. If array is having value then output datatable is equal to the array