DateTime to null

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alan T

    DateTime to null

    How do I set a DateTime field to null ?
    Hence set the DateTimePicker to null?


  • Shawn Wildermuth (C# MVP)

    #2
    Re: DateTime to null

    Hello Alan,

    You can't really. You can assign DbNull, but DateTime is a valuetype, therefore
    no null...


    Thanks,
    Shawn Wildermuth
    Speaker, Author and C# MVP

    How do I set a DateTime field to null ?
    Hence set the DateTimePicker to null?

    Comment

    • Joanna Carter [TeamB]

      #3
      Re: DateTime to null

      "Shawn Wildermuth (C# MVP)" <swildermuth@ne wsgroup.nospama écrit dans le
      message de news: fc24ddbdf9db8c8 78042b9b20c6@ms news.microsoft. com...

      | How do I set a DateTime field to null ?
      | Hence set the DateTimePicker to null?
      |
      | You can't really. You can assign DbNull, but DateTime is a valuetype,
      therefore
      | no null...

      But, if you are using C# 2.0, you can use Nullable<DateTi mewhich can be
      set to null and you can detect that, setting the database to DbNull where
      appropriate.

      Joanna

      --
      Joanna Carter [TeamB]
      Consultant Software Engineer


      Comment

      • Ignacio Machin \( .NET/ C# MVP \)

        #4
        Re: DateTime to null

        Hi,

        Will the DateTimePicker accept nullable types?
        AFAIK it does expect a DateTime.


        --
        --
        Ignacio Machin,
        ignacio.machin AT dot.state.fl.us
        Florida Department Of Transportation

        "Joanna Carter [TeamB]" <joanna@not.for .spamwrote in message
        news:OPglCekqGH A.2256@TK2MSFTN GP03.phx.gbl...
        "Shawn Wildermuth (C# MVP)" <swildermuth@ne wsgroup.nospama écrit dans le
        message de news: fc24ddbdf9db8c8 78042b9b20c6@ms news.microsoft. com...
        >
        | How do I set a DateTime field to null ?
        | Hence set the DateTimePicker to null?
        |
        | You can't really. You can assign DbNull, but DateTime is a valuetype,
        therefore
        | no null...
        >
        But, if you are using C# 2.0, you can use Nullable<DateTi mewhich can be
        set to null and you can detect that, setting the database to DbNull where
        appropriate.
        >
        Joanna
        >
        --
        Joanna Carter [TeamB]
        Consultant Software Engineer
        >
        >

        Comment

        • Bruce Wood

          #5
          Re: DateTime to null


          Ignacio Machin ( .NET/ C# MVP ) wrote:
          Hi,
          >
          Will the DateTimePicker accept nullable types?
          AFAIK it does expect a DateTime.
          See this link, under DateTimePicker:



          Comment

          Working...