Nullable types and datareader...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MobileBoy36

    #1

    Nullable types and datareader...

    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


  • Spam Catcher

    #2
    Re: Nullable types and datareader...

    "MobileBoy3 6" <MobileBoy36@gm ail.comwrote 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 :)

    Comment

    • RobinS

      #3
      Re: Nullable types and datareader...

      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.Has Value Then
      Console.WriteLi ne("IntegerDat a = " & IntegerData.ToS tring)
      Else
      Console.WriteLi ne("IntegerDat a = 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.ProductCo de
      End If

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

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

      "MobileBoy3 6" <MobileBoy36@gm ail.comwrote 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
      >
      >

      Comment

      • Jay B. Harlow

        #4
        Re: Nullable types and datareader...

        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.IsDB Null 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


        "MobileBoy3 6" <MobileBoy36@gm ail.comwrote 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
        >
        >

        Comment

        Working...