|
-
May 3rd, 2004, 10:43 AM
#1
Thread Starter
Frenzied Member
dateTime casting
I'm trying to set a property that is a datetime type (actually, I'm trying to use the sqldatetime type). in the db where the value is coming from, it's null. I get a cast error when trying to set the property. I've tried all sorts of stuff, can anyone give me an idea of how you resolve the problem?
-
May 3rd, 2004, 11:33 AM
#2
Thread Starter
Frenzied Member
well, I got the cast error to stop nagging me:
VB Code:
If reader.IsDBNull(30) Then
.Repaired = Nothing
Else
.Repaired = reader.Item("Repaired")
End If
but now, when I display that value, if it's NOTHING, the value is 12:00:00 AM (i guess by default). How do I get this to display blank?
-
May 3rd, 2004, 01:03 PM
#3
I wonder how many charact
.net datetime values cannot be null, (as an integer cannot be null... ints must either be a 0 , <1, or >1...)
If the db object is null, you could pass .Repaired a DateTime.MinValue (Jan 1, 1 AD).
Then inside the class that .Repaired is a property of, in the Get operator, if the DateTime = DateTime.MinValue, pass back nothing.
Last edited by nemaroller; May 3rd, 2004 at 01:17 PM.
-
May 3rd, 2004, 01:47 PM
#4
Thread Starter
Frenzied Member
ok, what I tried is :
VB Code:
Public Property Repaired() As DateTime
Get
If dteRepaired = DateTime.MinValue Then
Return Nothing
Else
Return dteRepaired
End If
End Get
Set(ByVal Value As DateTime)
dteRepaired = Value
End Set
If the db is sent a minvalue when inserting data, and it's checked when retrieving that data, i would say .repaired = nothing, is that what you are talking about?
BUT, isn't that the same as the method I used above?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|