Results 1 to 4 of 4

Thread: dateTime casting

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    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?

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    well, I got the cast error to stop nagging me:

    VB Code:
    1. If reader.IsDBNull(30) Then
    2.                         .Repaired = Nothing
    3.                     Else
    4.                         .Repaired = reader.Item("Repaired")
    5.                     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?

  3. #3
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    .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.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    ok, what I tried is :
    VB Code:
    1. Public Property Repaired() As DateTime
    2.        Get
    3.             If dteRepaired = DateTime.MinValue Then
    4.                 Return Nothing
    5.             Else
    6.                 Return dteRepaired
    7.             End If
    8.         End Get
    9.  
    10.         Set(ByVal Value As DateTime)
    11.             dteRepaired = Value
    12.         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
  •  



Click Here to Expand Forum to Full Width