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. Dates Problem

Dates Problem

Scheduled Pinned Locked Moved ASP.NET
help
3 Posts 3 Posters 1 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.
  • M Offline
    M Offline
    macca24
    wrote on last edited by
    #1

    I have a Search Page which contains dates and text fields. When I leave the Date fields blank an error is thrown in my code stating that cannot "Conversion from String to type Date is not valid". This happens because I am trying to assign the empty Date Text field to A Variable of type Date. If the Date Text field contains a Date there is no error thrown. Dim dtDateFrom As Date Dim dtDateTo As Date dtDateFrom = tbxDtFrom.Text dtDateTo = tbxDtTo.Text Anyone any ideas why this is happening macca

    J D 2 Replies Last reply
    0
    • M macca24

      I have a Search Page which contains dates and text fields. When I leave the Date fields blank an error is thrown in my code stating that cannot "Conversion from String to type Date is not valid". This happens because I am trying to assign the empty Date Text field to A Variable of type Date. If the Date Text field contains a Date there is no error thrown. Dim dtDateFrom As Date Dim dtDateTo As Date dtDateFrom = tbxDtFrom.Text dtDateTo = tbxDtTo.Text Anyone any ideas why this is happening macca

      J Offline
      J Offline
      Jesse Squire
      wrote on last edited by
      #2

      When the user does not enter a value, retrieving the Text property returns an empty string. You are attempting to perform an implicit conversion of "" to a date, which is not possible. You'll need to guard against this by testing to ensure that there is a value in the textbox before converting, or by using DateTime.TryParse. Hope that helps. :)

      --Jesse

      "... the internet's just a big porn library with some useful articles stuck in." - Rob Rodi

      1 Reply Last reply
      0
      • M macca24

        I have a Search Page which contains dates and text fields. When I leave the Date fields blank an error is thrown in my code stating that cannot "Conversion from String to type Date is not valid". This happens because I am trying to assign the empty Date Text field to A Variable of type Date. If the Date Text field contains a Date there is no error thrown. Dim dtDateFrom As Date Dim dtDateTo As Date dtDateFrom = tbxDtFrom.Text dtDateTo = tbxDtTo.Text Anyone any ideas why this is happening macca

        D Offline
        D Offline
        Darsh_3
        wrote on last edited by
        #3

        first check txt1 means the textbox having Date Value. if txt1.text="" then in query pass null keyword for that Date Field. i.e. here abc is the table with 2 columns frmdt(Date)& name(Text) insert into abc values(null,'"& txt2.text &"')

        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