Remove all nulls from a data table.

public void RemoveAllNullsFromDataTable(Data.DataTable TheDataTable)
{
 foreach (Data.DataRow RowInTable in TheDataTable.Rows) {
  foreach (Data.DataColumn ColumnInTable in TheDataTable.Columns) {
   int ColumnIndex = ColumnInTable.Ordinal;
   if (object.ReferenceEquals(RowInTable.Item(ColumnIndex), DBNull.Value)) {
    Type ColumnType = ColumnInTable.DataType;
    RowInTable.Item(ColumnIndex) = Convert.ChangeType(RowInTable.Item(ColumnIndex), ColumnType);
   }
  }
 }
}

No comments:

Post a Comment