Since LINQ supports querying and not updating, the best you could do is make use of its querying to get all the column info of a DataTable and then update your cell one-by-one.
One way to do it is by implementing a method whose input is DataTable to do the task:
private void dtChangeZeroToNull (DataTable dataTable){
List<string> dcNames = dataTable.Columns
.Cast<DataColumn>()
.Select(x => x.ColumnName)
.ToList(); //This querying of the Column Names, you could do with LINQ
foreach (DataRow row in dataTable.Rows) //This is the part where you update the cell one by one
foreach (string columnName in dcNames)
row[columnName] = (int)row[columnName] == 0 ? DBNull.Value : row[columnName];
}
And there you go.
Now, to change each cell whose value is 0 to DBNull in a DataTable, you can simply call the method:
dtChangeZeroToNull (dataTable);
Note: Seems like the DataTable.Rows and DataTable.Columns do not implement LINQ Select. Otherwise we could immediately do this
List<string> dtcolumnNames = dataTable.Columns.Select(x => x.ToString());
Without a need of Cast<DataColumn>
DataTablebut there's nothing wrong with using a loop. Or change the query that populates theDataTable.