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. Database & SysAdmin
  3. Database
  4. The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. The statement has been terminated.

The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. The statement has been terminated.

Scheduled Pinned Locked Moved Database
helpdesign
3 Posts 3 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.
  • M Offline
    M Offline
    Member 10437599
    wrote on last edited by
    #1

    Hi, i am a fresher.i am trying to insert values using front end,i am getting error The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. The statement has been terminated. During table creation for Date i used datetime datatype. in front end design i used code like this. Insert into Invoice(date) values('" + _Date + "'); i am using the DataGrid to Display the table in same page, i tried to give the date in both the format 1/2/2013 and 2013/01/02 but the error. plz help me to solve this Problem. plz provide the simple code to datetime conversion.

    R M 2 Replies Last reply
    0
    • M Member 10437599

      Hi, i am a fresher.i am trying to insert values using front end,i am getting error The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. The statement has been terminated. During table creation for Date i used datetime datatype. in front end design i used code like this. Insert into Invoice(date) values('" + _Date + "'); i am using the DataGrid to Display the table in same page, i tried to give the date in both the format 1/2/2013 and 2013/01/02 but the error. plz help me to solve this Problem. plz provide the simple code to datetime conversion.

      R Offline
      R Offline
      RedDk
      wrote on last edited by
      #2

      Member 10437599 wrote:

      '" + _Date + "'

      THAT is a string. Cast it as datetime. Like this ... CAST('"+_Date+"' AS [datetime])

      1 Reply Last reply
      0
      • M Member 10437599

        Hi, i am a fresher.i am trying to insert values using front end,i am getting error The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. The statement has been terminated. During table creation for Date i used datetime datatype. in front end design i used code like this. Insert into Invoice(date) values('" + _Date + "'); i am using the DataGrid to Display the table in same page, i tried to give the date in both the format 1/2/2013 and 2013/01/02 but the error. plz help me to solve this Problem. plz provide the simple code to datetime conversion.

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        You are doing a number of things wrong. You should use a datepicker instead of a textbox, this will help you control the format of your data, ALWAYS use the DATETIME data type, NEVER use varchar/string for datetime data. Learn to use parameterised queries[^] they will make you life a lot simpler and eliminate the data type issue (oh and make your code more secure). Instead of editing into a datagrid I recommend you use a detail control or a dialog to do your data entry, this give you much greater control easier to manage.

        Never underestimate the power of human stupidity RAH

        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