I want to delete the empty rows from the data table and need to write into another excel without any empty rows
you can just loop the data table and check the length of the row item and write it into the new sheet or you can write the select statement with the isnotnull condition and write the result into the target excel
Use this code to remove all column empty in the row.
DataTableName=DataTableName.Rows.Cast(Of DataRow)().Where(Function(row) Not row.ItemArray.All(Function(field) field Is DBNull.Value Or field.Equals(""))).CopyToDataTable()
If you want to remove the row based on the particular column value
If excel cell empty
Use this Query
(From row in dt.AsEnumerable()
where ( From p in dt.AsEnumearble()
where string.Is null or empty((string.Join(",",p.ItemArray)).Replace(",",""))
You will get it in an array of DataRows, you can convert to datatable by using dt.CopytoDataTable.
Here dt is your datatable variable.
thanks, For the answer , My problem solved
@arivu96 : I want to delete the row base on one column which contains null value.
I used below method to delete those rows
DataTableName=DataTableName.Select(“ColumnName = ‘’”).CopyToDataTable()
But it did not work.
Could you please Suggest.
I guess this should work.
Had the same problem. Solved with your solution. Thanks