Nullable object types

Discussion in 'ASP .Net' started by Nemisis, Aug 18, 2006.

  1. Nemisis

    Nemisis Guest

    Hi everyone, i have been stressing over this for the past hour or so,
    and just cannot figure it out, sorry if i am being stupid, but it is a
    friday! lol

    I have the following

    Private _ID as nullable (Of integer)

    Public Property ID()
    Get
    Return _ID
    End Get
    Set(ByVal value)
    _ID = value
    End Set
    End Property

    If i write
    Me.ID = 1234

    then the value in the debugger seems to update, great.

    But how do i get it back to null again? If i set ID = DBNull.Value, i
    get a build error. If i set ID = Nothing, then in the debugger, it
    says "Nullable object must have a value".

    If i am missing the point and being stupid, i do apoligise, i just
    really need to get this done.
     
    Nemisis, Aug 18, 2006
    #1
    1. Advertising

  2. Nemisis

    Patrice Guest

    Try :
    Me.ID = Nothing

    MsgBox(Me.ID.HasValue)



    Use Option Strict so that youi see you should make the propery IsNullable(Of
    Integer) instead of just Object...


    --
    Patrice

    "Nemisis" <> a écrit dans le message de news:
    ...
    > Hi everyone, i have been stressing over this for the past hour or so,
    > and just cannot figure it out, sorry if i am being stupid, but it is a
    > friday! lol
    >
    > I have the following
    >
    > Private _ID as nullable (Of integer)
    >
    > Public Property ID()
    > Get
    > Return _ID
    > End Get
    > Set(ByVal value)
    > _ID = value
    > End Set
    > End Property
    >
    > If i write
    > Me.ID = 1234
    >
    > then the value in the debugger seems to update, great.
    >
    > But how do i get it back to null again? If i set ID = DBNull.Value, i
    > get a build error. If i set ID = Nothing, then in the debugger, it
    > says "Nullable object must have a value".
    >
    > If i am missing the point and being stupid, i do apoligise, i just
    > really need to get this done.
    >
     
    Patrice, Aug 18, 2006
    #2
    1. Advertising

  3. Nemisis

    Nemisis Guest

    Patrice wrote:
    > Try :
    > Me.ID = Nothing
    >
    > MsgBox(Me.ID.HasValue)
    >
    >
    >
    > Use Option Strict so that youi see you should make the propery IsNullable(Of
    > Integer) instead of just Object...
    >
    >
    > --
    > Patrice
    >
    > "Nemisis" <> a écrit dans le message de news:
    > ...
    > > Hi everyone, i have been stressing over this for the past hour or so,
    > > and just cannot figure it out, sorry if i am being stupid, but it is a
    > > friday! lol
    > >
    > > I have the following
    > >
    > > Private _ID as nullable (Of integer)
    > >
    > > Public Property ID()
    > > Get
    > > Return _ID
    > > End Get
    > > Set(ByVal value)
    > > _ID = value
    > > End Set
    > > End Property
    > >
    > > If i write
    > > Me.ID = 1234
    > >
    > > then the value in the debugger seems to update, great.
    > >
    > > But how do i get it back to null again? If i set ID = DBNull.Value, i
    > > get a build error. If i set ID = Nothing, then in the debugger, it
    > > says "Nullable object must have a value".
    > >
    > > If i am missing the point and being stupid, i do apoligise, i just
    > > really need to get this done.
    > >

    I have tried setting the property to nothing and that still doesnt
    work. ???
     
    Nemisis, Aug 18, 2006
    #3
  4. Nemisis

    Patrice Guest

    As I said, you also have to correctly type your property :
    Private _ID As Nullable(Of Integer)

    Public Property ID() As Nullable(Of Integer)

    Get

    Return _ID

    End Get

    Set(ByVal value As Nullable(Of Integer))

    _ID = value

    End Set

    End Property

    You can then set the property to nothing :
    Me.ID = 1234

    Me.ID = Nothing

    MsgBox(Me.ID.HasValue)


    --
    Patrice

    "Nemisis" <> a écrit dans le message de news:
    ...

    Patrice wrote:
    > Try :
    > Me.ID = Nothing
    >
    > MsgBox(Me.ID.HasValue)
    >
    >
    >
    > Use Option Strict so that youi see you should make the propery
    > IsNullable(Of
    > Integer) instead of just Object...
    >
    >
    > --
    > Patrice
    >
    > "Nemisis" <> a écrit dans le message de news:
    > ...
    > > Hi everyone, i have been stressing over this for the past hour or so,
    > > and just cannot figure it out, sorry if i am being stupid, but it is a
    > > friday! lol
    > >
    > > I have the following
    > >
    > > Private _ID as nullable (Of integer)
    > >
    > > Public Property ID()
    > > Get
    > > Return _ID
    > > End Get
    > > Set(ByVal value)
    > > _ID = value
    > > End Set
    > > End Property
    > >
    > > If i write
    > > Me.ID = 1234
    > >
    > > then the value in the debugger seems to update, great.
    > >
    > > But how do i get it back to null again? If i set ID = DBNull.Value, i
    > > get a build error. If i set ID = Nothing, then in the debugger, it
    > > says "Nullable object must have a value".
    > >
    > > If i am missing the point and being stupid, i do apoligise, i just
    > > really need to get this done.
    > >

    I have tried setting the property to nothing and that still doesnt
    work. ???
     
    Patrice, Aug 21, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. buran

    nullable sqlparameter

    buran, Jul 17, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    547
    buran
    Jul 17, 2003
  2. Kevin Yu

    DateTime not nullable problem

    Kevin Yu, Jan 28, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    7,667
    MWells
    Jan 29, 2005
  3. scparker

    Nullable object must have a value.

    scparker, Jan 16, 2007, in forum: ASP .Net
    Replies:
    15
    Views:
    2,040
    scparker
    Jan 18, 2007
  4. =?Utf-8?B?emlubw==?=

    Nullable object must have a value

    =?Utf-8?B?emlubw==?=, Apr 13, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    13,095
    Steven Cheng[MSFT]
    Apr 16, 2007
  5. Jon

    Nullable types

    Jon, Oct 20, 2005, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    123
Loading...

Share This Page