Home All Groups Group Topic Archive Search About

Nullable types and datareader...

Author
12 Dec 2006 9:38 AM
MobileBoy36
Hi all,

Nullable types were announced as new handy stuff in .NET 2.0
But it seems like the datareader doesn't support nullable types.
You have still to check for "IsDbNull".
So, are Nullable Types useful at this moment? Do you get any benefit using
them (at this moment)?
Is Microsoft going to change this?

Best regards,
Mobile Boy

Author
12 Dec 2006 3:37 PM
Spam Catcher
"MobileBoy36" <MobileBo***@gmail.com> wrote in
news:457e7846$0$30037$ba620e4c@news.skynet.be:

> Nullable types were announced as new handy stuff in .NET 2.0
> But it seems like the datareader doesn't support nullable types.
> You have still to check for "IsDbNull".
> So, are Nullable Types useful at this moment? Do you get any benefit
> using them (at this moment)?
> Is Microsoft going to change this?

I don't think DBNull and Null are the same thing - that's why Nullable
types are not directly converted.

Take a look at LLBLGen Pro - it's a database framework from .NET. It has
support for Nullable types and the like... and MORE :)
Author
12 Dec 2006 10:37 PM
RobinS
Here's an example of using a nullable type. They are
good to use when you need to know if a number is 0 or Null,
because those are two different things, especially if you
are doing numerical calculations.

Dim IntegerData As Nullable(Of Integer)

If IntegerData.HasValue Then
   Console.WriteLine("IntegerData = " & IntegerData.ToString)
Else
   Console.WriteLine("IntegerData = Null.")
End If

If you read data from a database, you have to check for DBNull
and act accordingly.

  IntegerData = Nothing
  If NOT IsDBNull(myRow.ProductCode) Then
     IntegerData = myRow.ProductCode
  End If

Another syntax for this is:
  If myRow.ProductCode IsNot DbNull.Value Then
     ...

Robin S.
------------------------

Show quoteHide quote
"MobileBoy36" <MobileBo***@gmail.com> wrote in message
news:457e7846$0$30037$ba620e4c@news.skynet.be...
> Hi all,
>
> Nullable types were announced as new handy stuff in .NET 2.0
> But it seems like the datareader doesn't support nullable types.
> You have still to check for "IsDbNull".
> So, are Nullable Types useful at this moment? Do you get any benefit
> using them (at this moment)?
> Is Microsoft going to change this?
>
> Best regards,
> Mobile Boy
>
>
Author
14 Dec 2006 1:46 AM
Jay B. Harlow
Mobile Boy,
In addition to the other comments.

I find nullable types to be very useful on my domain (business) objects.

My data mappers (data objects) use DataReader.IsDBNull to decide if they
need to return Nothing or a value for the nullable types on the domain
objects.


--
Hope this helps
Jay B. Harlow
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


Show quoteHide quote
"MobileBoy36" <MobileBo***@gmail.com> wrote in message
news:457e7846$0$30037$ba620e4c@news.skynet.be...
> Hi all,
>
> Nullable types were announced as new handy stuff in .NET 2.0
> But it seems like the datareader doesn't support nullable types.
> You have still to check for "IsDbNull".
> So, are Nullable Types useful at this moment? Do you get any benefit using
> them (at this moment)?
> Is Microsoft going to change this?
>
> Best regards,
> Mobile Boy
>
>