I am extracting a data table from a website which may or may not have a table. When a table exists, it is extracted to PTDataTable, saved to an excel file, and processed using PTDataTable.Rows(n).Item(n).ToString. That all works perfectly.
I am attempting to handle the condition where there is no table by using an Else If conditioned with (not PTDataTable is nothing); however the condition is ignored when there is no table. I set a breakpoint on the Else If and step through. It drops right into the body as if PTDataTable exists, then issues error “There is no row at position 0” on the Else If condition which checks the first cell in the table.
The image shows the sequence and the status of PTDataTable at the breakpoint (first Else If) which shows Columns and Rows to be empty:
I found the “(not PTDataTable is nothing)” construct in the solution for a similar question but it clearly is not working here. The PTExit check is part of a Do While which permits several delayed attempts when there is no table found.
@EarlA
Also u can use linq for checking
Below is the linq code
In assign activity: isDataTableEmpty = (PTDataTable.AsEnumerable().Any()
The isDataTableEmpty should be a variable of Bool type
Then you can use the variable in if condition
Below is the explanation of Linq
The .AsEnumerable() method converts the PTDataTable into an enumerable collection, and the .Any() method checks if there are any elements in that collection. If the PTDataTable is empty, the .Any()` method will return False , and the isDataTableEmpty variable will be set to True
After extracting the table by extract datatable activity.
Use the PTDatatable.rows.Count > 2 then it has the rows in the datatable check with the If condition.