I need to check if excel sheet has data or no data, i am using below
dt.Rows.Count>1 or dt.Rows.Count<0
but in both cases it is surely giving output number for the sheet where there is data …( i am printing in msg box- dt.Rows.Count.ToString
But somehow for empty excel sheet it’s giving object reference error .
Please help me with condition which will check both the things
Shee1 is fully empty without headers and rows 0 but headers are there …
if above is true then I need to give business exception.
Surround the activities with the Try Catch. In the Try give Read Range Workbook. In the Catch give, BusinessRuleException and give the required exception.
Workbook has many sheets, in fact sheetname is as a transaction from queue.
Hence need to check if specific sheet has data or no data
I am using rows.count but if there r no headers n full blank sheet with valid sheet name then it’s giving obj ref error
Assign Activity:
Left side: isEmpty
Right side: dt IsNot Nothing AndAlso dt.Rows.Count > 0 AndAlso dt.Rows(0).ItemArray.Any(Function(rowValue) Not String.IsNullOrEmpty(rowValue.ToString()))
If isEmpty Then
The DataTable has data (excluding headers)
Your code for handling non-empty DataTable goes here
Else
The DataTable is either null, empty, or contains only headers
Your code for handling empty DataTable goes here
End
if excel sheet is completely blank, read range activity itself will throw exception,
better you keep read range activity in Try catch, if flow goes to try catch, means sheet does not have data(not even headers),
to check if there is data except header row, use dt.rows.count>0
If u have not initialized the dt
dt= new system.data.datatable while creating then u need to chk
if( dt Is Nothing) then Datatable empty
Else if dt.rows.count>0 then not empty
—If you hv initialised then for empty sheet—
Check dt.rows.count = 0