hello everyone,
I am reading an excel file with the range in the read range A1:F100 as the file has repeated columns that I do not need for the purpose of the process.
The Datatable, if I print it, comes up empty (there are no rows valued in the file), but from the DT.Rows.Count comes up 99 rows.
When I try to delete the empty rows with the following query.
DataTableName=DataTableName.Rows.Cast(Of DataRow)().Where(Function(row) Not row.ItemArray.All(Function(field) field Is DBNull.Value Or field.Equals(ββ))).CopyToDataTable()
It returns the following error:
Source contains no datarows
Instead it works if at least one row is valued.
My goal is to know if there are empty or valorized rows, and to handle the valorized ones, how do I actually remove the empty rows?
this is the datatable output, as you see it is empty but there are 99 rows present (doing dt.rows.count)
At this point if I try to delete the blank rows with the query written in the first message, it goes into error as:
source contains no datarows
I have no problem instead if at least one of the rows is populated (in that case the datatable has 1 full row and 98 empty rows, which it deletes correctly)
The Query gives out an Error if there are no Non-Empty rows present, This is because it is trying to convert empty rows into a Datatable Directly. Instead we could first convert the Filtered rows into an Array/List and then Convert to Datatable if rows exist in the Array. A detailed explanation is provided in the below Tutorial Post :