Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Cast from string "" to type 'Date' is not valid

Cast from string "" to type 'Date' is not valid

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-net
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rs_net
    wrote on last edited by
    #1

    Hello all, I have a textbox in my asp.net (vb.net) aplicattion, I need to assign it's value to a Variable of type DATE, but it's not a required field, so sometimes I want to send a blank field. I declared a variable as a date datatype and when it=B4s going to receive the content of the text field, it shows the following error "Cast from string "" to type 'Date' is not valid" What should I do to handle this problem. rs_net

    G I 2 Replies Last reply
    0
    • R rs_net

      Hello all, I have a textbox in my asp.net (vb.net) aplicattion, I need to assign it's value to a Variable of type DATE, but it's not a required field, so sometimes I want to send a blank field. I declared a variable as a date datatype and when it=B4s going to receive the content of the text field, it shows the following error "Cast from string "" to type 'Date' is not valid" What should I do to handle this problem. rs_net

      G Offline
      G Offline
      George L Jackson
      wrote on last edited by
      #2

      You can not convert an Emtpy String to a date. C#: if (TextBox1.Text != String.Empty) {   // Convert String to Date here }

      R 1 Reply Last reply
      0
      • G George L Jackson

        You can not convert an Emtpy String to a date. C#: if (TextBox1.Text != String.Empty) {   // Convert String to Date here }

        R Offline
        R Offline
        rs_net
        wrote on last edited by
        #3

        hi, Is there anyway to store the empty value like "00/00/0000" or 0 for the datetime column? rs_net

        G 1 Reply Last reply
        0
        • R rs_net

          hi, Is there anyway to store the empty value like "00/00/0000" or 0 for the datetime column? rs_net

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          A DateTime structure doesn't have an empty value. You can use some other value to represent that value, like DateTime.MinValue or DateTime.MaxValue. If you store the value in a database, you can set the field to null (DbNull.Value). --- b { font-weight: normal; }

          1 Reply Last reply
          0
          • R rs_net

            Hello all, I have a textbox in my asp.net (vb.net) aplicattion, I need to assign it's value to a Variable of type DATE, but it's not a required field, so sometimes I want to send a blank field. I declared a variable as a date datatype and when it=B4s going to receive the content of the text field, it shows the following error "Cast from string "" to type 'Date' is not valid" What should I do to handle this problem. rs_net

            I Offline
            I Offline
            Ista
            wrote on last edited by
            #5

            The proper way would be although this is c# try { DateTime dt = DateTime.Parse( txtDate.Text ); } catch(){} you could create a class and just pass the date and if its invalid don't create the object. 1 line of code equals many bugs. So don't write any!!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups