I was wondering what the correct way to catch an exception for an empty “select” on a data table is. For example, if we have two variables: unfilteredDT and filteredDT. I want to apply a set of filter criteria to unfilteredDT and then assign that to filteredDT, which I know how to do, but if there are no data rows matching that criteria, an error is thrown because there are no data rows to assign.
I tried using an if statement to test the select prior to assigning so that I can skip that step but that also throws an error (I’m assuming because of the CopyToDataTable piece):
IF
unfilteredDT.Select(“[Status]=‘Open’ AND [Description]=‘Research Client Check Copy’”).CopyToDataTable.Rows.Count = 0
THEN
(do nothing)
ELSE
Assign to filteredDT and do other stuff.
Hopefully that makes sense the way I’m trying to lay it out. I get work item data in my unfilteredDT from scraping but I need a way to test that there are items meeting my criteria before I assign it in any way or it throws an error which retries the transaction according to my retries config setting.
Create DataRow() variable to assign the unfilteredDT.Select(“[Status]=‘Open’ AND [Description]=‘Research Client Check Copy’”) expression, then just do variable.Count = 0
Please disregard – I realize now, after more research, that a select on a data table turns it into an array of data rows. All I needed to use was the following:
unfilteredDT.Select(“[Status]=‘Open’ AND [Description]=‘Research Client Check Copy’”).Length = 0
As soon as I tried to use the .CopyToDataTable piece, I would get the error again because there is no data to copy to a data table (temporarily or via assign). Hopefully that makes sense. The main takeaway is that, as soon as you use a select statement on a data table, you’re now working with an array and you want to do your tests against that array before you push it back into a data table.
Hopefully this helps someone – didn’t want to leave this thread without resolution.