Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can remove rows with null values in a dataTable by using the following code:

dataTable.Rows.Cast<DataRow>().Where(row => row.ItemArray.All(field => field is DBNull)).ToList().ForEach(row => dataTable.Rows.Remove(row));

This code will loop through all the rows in the dataTable and check if all the fields in the row are null using the LINQ method "All". If all the fields are null, the row will be removed from the dataTable using the "Remove" method.

Note: Make sure to replace "dataTable" with the name of your actual dataTable variable.