Q:

Dataset field DBNull -> int?

SQLServer int field. Value sometimes null.
DataAdapter fills dataset OK and can display data in DatagridView OK.
When trying to retrieve the data programmatically from the dataset the Dataset field retrieval code throws a StronglyTypedException error.
 [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    public int curr_reading {
        get {
            try {
                return ((int)(this[this.tableHistory.curr_readingColumn]));
            }
            catch (global::System.InvalidCastException e) {
                throw new global::System.Data.StrongTypingException("The value for column \'curr_reading\' in table \'History\' is DBNull.", e);
            }

Got past this by checking for DBNull in the get accessor and returning null but...
When the dataset structure  is modified (Still developing) my changes (unsurprisingly) are gone.  
What is the best way to handle this situation? 
It seems I am stuck with dealing with it at the dataset level.
Is there some sort of attribute that can tell the auto code generator to leave the changes in place?  

A:

In the typed dataset designer there is the nullvalue property.
By default its value is throw exception (hence your generated code)
You can set it to the desired default value.. ie. 0.
Then it will return 0 instead of an exception. (other code is generated)
VS2008 :This works directly in the dataset designer.
VS2005 : It only works for strings in the designer but you can directly edit the XSD an set the property msprop:nullValue="0"

A:

Leave the auto-generated code alone. There's no way to "intercept" it getting generated so any changes you do make are guaranteed to get blown away sooner or later.
.NET (well at least the .NET 2.0 system.data bits) will not convert from DBNull into anything else. This sucks but you can't do anything about it.
Write an extension method called ToNullable() or similar: it can do this:

.
public static Nullable<T> ToNullable(this object x){
    if(x == DBNull.Value)
       return default(T); // return null thing
    else
       return (T)x;
}

then you can do
int? thing = DataRow["column"].ToNullable<int>();

A:

The dataset will have a boolean property to indicate null. 
int curr_reading = ( Iscurr_readingColumnNull) ? 
                   <default_value> : row.curr_readingColumn;

