Link to home
Start Free TrialLog in
Avatar of dba123
dba123

asked on

System Null Exception on DateTime Null field that's being passed

This is driving me nuts.  Ok, I created a property in our User class.  I then try to use it in a code-behind class

User class has the following code in this order:

Private _EBookPolicyAccepted As DateTime = DateTime.MinValue

    Public Property EBookPolicyAccepted() As DateTime
        Get
            Return _EBookPolicyAccepted
        End Get
        Set(ByVal Value As DateTime)
            _EBookPolicyAccepted = Value
        End Set
    End Property

    Private Sub InitValues(ByRef dr As SqlDataReader)
     ...
            If Not IsDBNull(dr("EBookPolicyAccepted")) Then
                _EBookPolicyAccepted = DBConvert.CvDate(dr("EBookPolicyAccepted"))
            End If
     ...
    End Sub

The user class compiles ok.

Now, in the code-behind of the page I'm working on I have code in this order as so:

    Dim cUser As New CurrentUser
    Dim vUser As New AAY.VC.User(cUser.UserID)

...
    Private ReadOnly Property EbookPolicyAccepted() As DateTime
        Get
            Return vUser.EBookPolicyAccepted
        End Get
    End Property

...

    Private Sub BookRepeater_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles BookRepeater.ItemDataBound

...
            ElseIf (Me.EbookPolicyAccepted = DateTime.MinValue) Then
                eBookPolicyMessage.Text = "something here"
...
End Sub

I keep getting an error on this line stating a System Null Exception.  I know that the default value in the database for that field is NULL but not sure how to handle and pass it so that I can do that last check in that If statement you see.  Obviously I'm not doing this correctly so not sure how.
ASKER CERTIFIED SOLUTION
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dba123
dba123

ASKER

someone updated a stored proc I was using and fricking took out a field.  That was the problem....ahhh