In the dataset designer there is a option on the column for NullValue (set via the xsd as msprop:nullValue) that lets you configure the column behavior when null, throw an exception, return a null or string.empty for strings.
As this is a codegen behavior, it's not something you can set directly on an untyped datacolumn. It also only works for string types, not value types in the designer. You can get in the xsd and do something like this for a int column:
<xs:element name="Size" type="xs:int" msprop:nullValue="-1" .../>
Of course the typed datarow is a partial class so you can always do something like this
[code]
public partial class DataSet1
{
public partial class NullTestRow : global::System.Data.DataRow
{
public int? SizeNullable
{
get
{
if (this.IsSizeNull())
{
return null;
}
else
{
return ((int)(this[this.tableNullTest.SizeColumn]));
}
}
}
}
}
[/code]
Wonder if you could write a postSharp aspect that would add all these in for you at compile time?
P.S. Anyone know where the list of tags you can use on here is, quote, video etc...