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("EBookPolicyAc cepted")) Then
_EBookPolicyAccepted = DBConvert.CvDate(dr("EBook PolicyAcce pted"))
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. RepeaterIt emEventArg s) 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.
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("EBookPolicyAc
_EBookPolicyAccepted = DBConvert.CvDate(dr("EBook
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
...
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
LOL!
ASKER