How to check if datatable has no rows?

Hi, I would like to filter the rows.

Code:
gue.Select(“[Client] like ‘“+Name+”’ AND [Agent] like ‘DB2’ AND [Type] like '”+service1+“'”).CopyToDataTable

The agent is not fixed. It’s either ‘DB2’ or ‘SQL Server’.

So when I hardcoded the agent to be ‘DB2’, the error was thrown to the assign that the source contains no datarows.

I would like to look for this row this value, if it is not true, find another value.

Below is a sample of the dt
image

I tried this : serviceCatalogue.Select(“[Agent] like ‘SQL Server’”).Length > 0 - but does not work

image

Any solutions?

Thank you xoxo

@sangasangasanga

Below method will return the rows count

yourdatatable.rows.count

To check datatable has rows

yourdatatable.rows.count > 0

Regards,
ranjith

1 Like

Hi, your solution isn’t working. The error is still there


Instead of just checking for the count of Rows, Check if (dt3 is NOT nothing), after which check if dt3.Rows.count>0.

@sangasangasanga

Try to print the rows count before IF activity.

Hi @siddharth

How do you do this? I tried IsNotNothing(dt3) but does not work

In your if condition, write one of these:

  1. dt3 is nothing
  2. isNothing(dt3)

Your else part will contain the code for when the table reference exists.

Check this and let me know if this solves your problem.

Hi @sangasangasanga,

Try this…

image

Regards
Balamurugan.S

Hi guys @ranjith @siddharth @balupad14, I tried all your suggestions. It was not working. Then I realized the problem isn’t in the ‘for each row’. It is the assigning of the filter rows. I have updated the question again. Pls take a look and help me if you can.

Thank you.

split CopyToDatatable expression in two steps

First Array(of Datarow) filteredRows= gue.Select(“[Client] like ‘ “+Name+” ’ AND [Agent] like ‘DB2’ AND [Type] like ‘”+service1+“’”)

Than assign newDt = If(filteredRows.Any, filteredRows.CopyToDatatable, gue.Clone)

1 Like