Datatable.rows.count returns blank output

Hello,

Can anyone please help me understand why datatable returns blank output for zero records. I was expecting it to return “0” FOR DT.ROWS.COUNT but my message box is displaying blank value.

I don’t have any idea as to why it is blank. As per my code, it should return zero as there are no rows in the excel sheet

Thanks
Selva

Tested a few instances with Read Range inside Excel Application Scope and it is working fine for me.
Can you check if the dt is not empty? i mean if the excel was not read properly?
Maybe share a bit of insight or screenshots on how the dt is getting populated.

Hello @kaderms, Actually I am comparing two excel files.

  1. Download an excel attachment and read/store it as dt1 - Success
  2. Copy data from citrix app and paste it in another excel which is dt2 - Success
  3. Filter dt2 based on certain condition and store it in dt3 - Success
  4. Compare both dt1 and dt2.
  5. dt1 - outer for loop, dt2 - inner for loop
  6. Check for certain conditions between the columns ( Ex: row.item(0).toString = row1.item(0).to string)
  7. Step 6 is like primary key. If primary key records match, then copy the records from dt1 and paste it in dt2.
  8. In my case, as there are no matching records, I have empty sheet which is expected
  9. However when I run dt2.rows.count - it is giving blank row in message box display.
  10. I guess it’s a header issue. But it’s not visible… Might be column1, column2 etc
  11. how do I get the count of dt2

I tried filtering empty rows but in vain. that resulted in error as well. Column1 doesn’t exist/invalid column name

I was playing around with your scenario but am not able to replicate your issue the same way.
Even if I read a sheet which has all empty cells and not even a header, I still get the dt.rows.count as 1 (might be an issue. Planning to initiate a new topic with proper details. Waiting for this thread to go on).
But even then I dont get row count as blank!

Try debugging a bit. Use Output Data Table activity to store the DT in a variable and display it using Write Line.

To be on the same page, hope you too are using Read Range activity within Excel Application Scope. Also am trying this on .xlsx file, with Excel 2016. Not sure if that matters. Just in case…

You mean to say, even without any records or headers in Excel sheet, does the row count return as 1? Moreover what is the difference between having two separate excel application scope under a sequence and one excel application scope inside the other?

The variable have scopes have been declared at the global level

Yes… This is what I tried.

image

Excel Application Scope is more of a container like an Attach Window activity. Whatever actions you do within that container gets performed on the sheet in the scope.
I am not sure how efficient / advisable it is to use Excel Application Scope within another, though it might work. I would have used two separate containers rather than complicating it, until really necessary.

Can you please check your variable scope. May be two variable with same name have been declared, One in Global Scope and one in Excel Application Scope. If So, then delete the variable declared in Excel Application Scope. It should work.

2 Likes

Sure. Will have a look into it. Thanks for your response @Santan_Barnwal, @kaderms

1 Like

@Santan_Barnwal @kaderms. Guys, can you please advise me on how to approach this?

I am aware of how to add a new column with default value but can you please let me know how to solve this?

@Santan_Barnwal @kaderms - Guys, can you help me with the below post?