Typing to Nullable (Of Date) vs typing to Date

Discussion in 'ASP .Net' started by JimLad, Jan 26, 2010.

  1. JimLad

    JimLad Guest

    This is just an example of the crux of the problem:

    CType(CObj("11/09/2009"), Date)
    Returns date object as expected.

    CType(CObj("11/09/2009"), Nullable(of Date))
    In QuickWatch returns the string.
    At runtime crashes out with invalid Cast.

    Can someone explain the different behaviour to me please? I don't see
    why one works and one doesn't.

    Also assuming I have a gridview returning IOrderedDictionary, how do I
    convert blanks strings to nothing and non-blank string to date? Do I
    have to resort to IIF? Given that Nullable(of Date) can't cope with
    different base types cast as objects I guess I'll have to...

    In the case above I had a function returning a string, but when
    'Nothing' was returned it got converted to an empty string. Then I
    tried returning the string date or nothing in an object, but that
    still didn't work.

    I'm probably being a bit stupid. Apoplogies if the answer is simple...

    James
     
    JimLad, Jan 26, 2010
    #1
    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:
    549
    buran
    Jul 17, 2003
  2. Kevin Yu

    DateTime not nullable problem

    Kevin Yu, Jan 28, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    7,669
    MWells
    Jan 29, 2005
  3. Jacques Wentworth

    Property 'Keycode' is non-nullable

    Jacques Wentworth, Mar 11, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    3,668
    Jacques Wentworth
    Mar 11, 2005
  4. Child

    Nullable DateTime variables

    Child, May 3, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    24,637
    elizas
    May 7, 2010
  5. Mark Rae

    Nullable strings as parameters

    Mark Rae, Jan 25, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    21,500
    Mark Rae
    Jan 25, 2006
Loading...

Share This Page