Select dt empty rows - The source contains no DataRows

Hello everyone,

the following select returns me the following error when the datatable is empty: The source contains no DataRows.

Since the excel file consists of columns that have the same header, I was forced to read the file with a fixed range “A1:AC100”, this results in that even though the db is empty, it returns me a .Count of 99 rows.

Since I need to perform a check on the existence of data in the table, I thought I would use the following select to clean up the excess rows: dt.Rows.Cast(Of DataRow)().Where(Function(row) Not row.ItemArray.All(Function(field) field Is DBNull.Value Or field.Equals(“”))).CopyToDataTable()

How can I proceed?

Hi @etasca

Check out this tutorial

Another way You can try with Try catch activity

In the Try → Use the Assign activity

Dt = dt.Rows.Cast(Of DataRow)().Where(Function(row) Not row.ItemArray.All(Function(field) field Is DBNull.Value Or field.Equals(“”))).CopyToDataTable()

Inside the Catch → Use Assign activity

dt = New dataTable

Regards
Gokul

Hi,

Can you try as the following?

First, extract non blank line as DataRow array

arrDr = dt.Rows.Cast(Of DataRow)().Where(Function(row) Not row.ItemArray.All(Function(field) field Is DBNull.Value Or field.Equals(""))).ToArray()

Then check arrDr. If there is an item, use CopyToDataTable(). If not, use dt.Clone()

Regards,

1 Like

Thanks, it works!!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.