Friday, September 09, 2005

Since nullable has been baked into .NET, I had to see if that carried over to ADO.NET. Now I know that datasets' behavior with Nullable types was so broken that it was removed from the scope of  .NET 2.0, but I wanted to go back and look at my previous tests with dbnull and Nullable types.

Nullable may be "fixed", but there is still no correlation between them. I know that the fix was for totally different reasons, but I just still had to see.

It is still necessary to test for a dbnull before trying to populate a Nullable<DateTime>, for example.

Any attempts to return date data that is nullable with a datareader.GetDateTime() will give a runtime error. DataReader knows this value is a dbnull, but you will just have to check for yourself and do the little bit of extra work.

nulld Nullable<DateTime>;

'get some data into a reader and read it

if (myReader.IsDBNull(mycolumn))
{
 nulld=null;
else
 nulld=myReader.GetDateTime(mycolumn);
}



Don't Forget: www.acehaid.org
Friday, September 09, 2005 2:28:36 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
All comments require the approval of the site owner before being displayed.
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview