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. General Programming
  3. Visual Basic
  4. conversion of char data type to datetime data type resulted in out of range datetime value Error in VB.NET [modified]

conversion of char data type to datetime data type resulted in out of range datetime value Error in VB.NET [modified]

Scheduled Pinned Locked Moved Visual Basic
helpcsharptutorial
7 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.
  • S Offline
    S Offline
    samsonx
    wrote on last edited by
    #1

    Hi My code displays the error in top

    cmd = New SqlCommand("spStudent", con1)
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Parameters.Add(New SqlParameter("@EnterDate", SqlDbType.DateTime, 8))
    cmd.Parameters("@EnterDate").Value = "01/09/2009"
    cmd.CommandTimeout = 1800
    cmd.ExecuteNonQuery()
    Sda = New SqlDataAdapter(cmd)
    Sda.Fill(dt)

    How to resolve this problem... please help

    Regards, Samson

    modified on Friday, January 9, 2009 5:35 AM

    J L G 4 Replies Last reply
    0
    • S samsonx

      Hi My code displays the error in top

      cmd = New SqlCommand("spStudent", con1)
      cmd.CommandType = CommandType.StoredProcedure
      cmd.Parameters.Add(New SqlParameter("@EnterDate", SqlDbType.DateTime, 8))
      cmd.Parameters("@EnterDate").Value = "01/09/2009"
      cmd.CommandTimeout = 1800
      cmd.ExecuteNonQuery()
      Sda = New SqlDataAdapter(cmd)
      Sda.Fill(dt)

      How to resolve this problem... please help

      Regards, Samson

      modified on Friday, January 9, 2009 5:35 AM

      J Offline
      J Offline
      Jay Royall
      wrote on last edited by
      #2

      Try:

      cmd.Parameters("@EnterDate").Value = New Date(1, 9, 2009)

      S 1 Reply Last reply
      0
      • J Jay Royall

        Try:

        cmd.Parameters("@EnterDate").Value = New Date(1, 9, 2009)

        S Offline
        S Offline
        samsonx
        wrote on last edited by
        #3

        cmd.Parameters("@EnterDate").Value = New Date(1, 9, 2009) This one is Date(year, month, Date) Format. But my Format is MM/dd/yyyy.... Please help further

        With Regards, Samson

        J 1 Reply Last reply
        0
        • S samsonx

          cmd.Parameters("@EnterDate").Value = New Date(1, 9, 2009) This one is Date(year, month, Date) Format. But my Format is MM/dd/yyyy.... Please help further

          With Regards, Samson

          J Offline
          J Offline
          Jay Royall
          wrote on last edited by
          #4

          Ah I see, sorry, I misread your post. Unfortuanately I can't offer any more help, sorry.

          1 Reply Last reply
          0
          • S samsonx

            Hi My code displays the error in top

            cmd = New SqlCommand("spStudent", con1)
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Parameters.Add(New SqlParameter("@EnterDate", SqlDbType.DateTime, 8))
            cmd.Parameters("@EnterDate").Value = "01/09/2009"
            cmd.CommandTimeout = 1800
            cmd.ExecuteNonQuery()
            Sda = New SqlDataAdapter(cmd)
            Sda.Fill(dt)

            How to resolve this problem... please help

            Regards, Samson

            modified on Friday, January 9, 2009 5:35 AM

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            samsonx wrote:

            cmd.Parameters("@EnterDate").Value = "01/09/2009"

            Convert "01/09/2009" to dateTime variable and then assign the value to parameter. The format of DateTime does not matter during the Saving of information.

            1 Reply Last reply
            0
            • S samsonx

              Hi My code displays the error in top

              cmd = New SqlCommand("spStudent", con1)
              cmd.CommandType = CommandType.StoredProcedure
              cmd.Parameters.Add(New SqlParameter("@EnterDate", SqlDbType.DateTime, 8))
              cmd.Parameters("@EnterDate").Value = "01/09/2009"
              cmd.CommandTimeout = 1800
              cmd.ExecuteNonQuery()
              Sda = New SqlDataAdapter(cmd)
              Sda.Fill(dt)

              How to resolve this problem... please help

              Regards, Samson

              modified on Friday, January 9, 2009 5:35 AM

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

              That means that the database doesn't use the same date format that you use, and is parsing it to a completely different date, like perhaps '0001-09-09'. This is outside the range of dates that the datetime type in the database can handle, hence that specific error message. Parse the string into a DateTime value before you put it in the parameter: cmd.Parameters("@EnterDate").Value = DateTime.ParseExact("01/09/2009", "MM/dd/yyyy", CultureInfo.InvariantCulture)

              Despite everything, the person most likely to be fooling you next is yourself.

              1 Reply Last reply
              0
              • S samsonx

                Hi My code displays the error in top

                cmd = New SqlCommand("spStudent", con1)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add(New SqlParameter("@EnterDate", SqlDbType.DateTime, 8))
                cmd.Parameters("@EnterDate").Value = "01/09/2009"
                cmd.CommandTimeout = 1800
                cmd.ExecuteNonQuery()
                Sda = New SqlDataAdapter(cmd)
                Sda.Fill(dt)

                How to resolve this problem... please help

                Regards, Samson

                modified on Friday, January 9, 2009 5:35 AM

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Try date format with cmd.Parameters("@EnterDate").Value = cdate("#01/09/2009#")

                mailto: anubhava.prodata@gmail.com

                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