The source contains no DataRows when filtering empty datatable

Hi Everyone,

I need to filter DT1 based on CreateDate Column older than 5 days and create a DT2. So I am using Assign activity
DT2 = DT1.Select(“[CreateDate] <= “+DateTime.Parse(Date.Today.AddDays(-5).ToString).ToString +”#”).CopyToDataTable

sometime this returns 0 data rows and workflow fails on this assign activity. Error: The source contains no DataRows.

If above code returns some data rows, rest of the code is working fine as expected.

Can someone help me how can I handle if source returns 0 datarow? Thanks

Hi before assigning the datatable use a if condition with the below condition

DT1.Select(“[CreateDate] <= “+DateTime.Parse(Date.Today.AddDays(-5).ToString).ToString +”#”).Count<>0

If the condition is true then use the assign activitiy

DT2= DT1.Select(“[CreateDate] <= “+DateTime.Parse(Date.Today.AddDays(-5).ToString).ToString +”#”).CopyToDataTable

Else do nothing

Mark it as solution if it helps you

Regards

Nived N

Happy Automation

Thank you Nived. I worked as expected. I was doing Row.Count instead of just Count in IF condition.

1 Like

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