Im trying to filter out blank cells in a CSV and than write it into XLSX file but the filter part keep on showing Assign: The source contains no DataRows Error
Make sure the first column is not blank. According to error message, it seems first column is blank for all records.
means there are no empty rows in the first column can you check whether are empty cells in that particular column or not
dt.Asenumerable.where(function(a) a(0).tostring.trim<>"").copytodatatable
try this once
My first column for my csv file isn’t empty though. Yesterday I tried with the same code and same data from the CSV file it works, but when i tried again today its not.
I tried this as well it didnt work
Hi @Lee4216
Try this
dt.AsEnumerable().Where(Function(row) Not String.IsNullOrEmpty(row.Field(Of String)(0))).CopyToDataTable()
and also check whether the data table contains data or not by using dt.Rows.Count in a messagebox.
or try with Filter Data Table activity
Hi @Lee4216
results = (From Row In ExtractDataTable.AsEnumerable()
Where Not String.IsNullOrWhiteSpace(Row.ItemArray(0).ToString())
Select Row).ToList()
If results.Count > 0 Then
Dim filteredDataTable As DataTable = results.CopyToDataTable()
Else
’ Handle the case where no rows meet the criteria
’ Maybe create an empty DataTable with the same schema
filteredDataTable As DataTable = ExtractDataTable.Clone()
Hope this helps
Your code logic is correct.
just double check the CSV file manually. Mostly probably something is changed in it.
If possible screenshot would be great.
I tried the 2 methods u mentioned and it didnt work. My message box says 0
Ok, while running my code, I managed to get the message output of 600 which is correct. The filter part now shows no error but it doesnt filter out the blank cells to the XLSX file
if i put it to this format is it ok?
No need to take 0,1,2,3 columns if you want to remove the blank rows with respect to 1st column then give only 0 it will delete all empty rows from 1st column and other columns.
It did work but until but not fully, left a few more cells that are not deleted. Btw Im check the 2nd column for any blanks, so for the Filter Data Table I set it to Column 1.

Its correct right?
ExtractDataTable.AsEnumerable() _
.Where(Function(row) row.Field(Of String)(1) IsNot Nothing AndAlso Not String.IsNullOrEmpty(row.Field(Of String)(1).ToString())) _
.CopyToDataTable()
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.