I have a DataTable, which has a number of columns. Some of those columns are nullable.
DataTable dt; // Value set.
DataRow dr; // Value set.
// dr["A"] is populated from T-SQL column defined as: int NULL
int? a = dr["A"] as int?;
int? a = (dr["A"] != DBNull.Value) ? (int)dr["A"] : 0;
The LINQ to DataSets chapter of LINQ in Action is a good read.
One thing you'll see is the
Field<T> extension method, which is used as follows:-
int? x = dt.Field<int?>( "Field" );
int y = dt.Field<int?>( "Field" ) ?? 0;
var z = dt.Field<int?>( "Field" );