Insert DateTime Value In DB Table?

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

    Insert DateTime Value In DB Table?

    A SQL Server 2005 DB table has 4 columns namely "ID" (IDENTITY int
    column), "FirstName" (varchar(50)), "LastName" (varchar(50)) & "DOB"
    (datetime). Now when I am trying to add a new row using the following
    INSERT statement:

    sqlDapter.Inser tCommand = New SqlCommand
    sqlDapter.Inser tCommand.Comman dText = "INSERT INTO UserDetailss
    VALUES('bobby', 'simpson','" & Now() & "')"
    sqlDapter.Inser tCommand.Connec tion = sqlConn
    sqlDapter.Updat e(dSet, "UserDetail s")
    'Response.Write ("INSERT INTO UserDetailss VALUES('bobby', 'simpson','" &
    Now() & "')"

    the following error gets generated pointing to the Update line:

    The conversion of a char data type to a datetime data type resulted in
    an out-of-range datetime value.

    I even tried using the different DateTime Format functions but none of
    them work. WHere am I going wrong?

    Thanks

    Arpan

  • Kevin Spencer

    #2
    Re: Insert DateTime Value In DB Table?

    DateTime.Now is a DateTime value, not a string. Try using
    DateTime.Now.To String()

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    Chicken Salad Surgery

    Orange you bland I stopped splaying bananas?


    "Arpan" <arpan_de@hotma il.comwrote in message
    news:1155822315 .014394.128380@ b28g2000cwb.goo glegroups.com.. .
    >A SQL Server 2005 DB table has 4 columns namely "ID" (IDENTITY int
    column), "FirstName" (varchar(50)), "LastName" (varchar(50)) & "DOB"
    (datetime). Now when I am trying to add a new row using the following
    INSERT statement:
    >
    sqlDapter.Inser tCommand = New SqlCommand
    sqlDapter.Inser tCommand.Comman dText = "INSERT INTO UserDetailss
    VALUES('bobby', 'simpson','" & Now() & "')"
    sqlDapter.Inser tCommand.Connec tion = sqlConn
    sqlDapter.Updat e(dSet, "UserDetail s")
    'Response.Write ("INSERT INTO UserDetailss VALUES('bobby', 'simpson','" &
    Now() & "')"
    >
    the following error gets generated pointing to the Update line:
    >
    The conversion of a char data type to a datetime data type resulted in
    an out-of-range datetime value.
    >
    I even tried using the different DateTime Format functions but none of
    them work. WHere am I going wrong?
    >
    Thanks
    >
    Arpan
    >

    Comment

    • Arpan

      #3
      Re: Insert DateTime Value In DB Table?

      DateTime.Now is a DateTime value, not a string. Try using
      DateTime.Now.To String()
      Kevin, DateTime.Now.To String() still generates the same out-of-range
      error & why wouldn't it? The data type of the column named "DOB" in the
      DB table (& hence in the DataSet as well) is "datetime" which means SQL
      Server is expecting a datetime record in that column; so converting it
      to string - how will that work?

      Please correct me if I am wrong.

      Thanks,

      Regards,

      Arpan

      Kevin Spencer wrote:
      DateTime.Now is a DateTime value, not a string. Try using
      DateTime.Now.To String()
      >
      --
      HTH,
      >
      Kevin Spencer
      Microsoft MVP
      Chicken Salad Surgery
      >
      Orange you bland I stopped splaying bananas?
      >
      >
      "Arpan" <arpan_de@hotma il.comwrote in message
      news:1155822315 .014394.128380@ b28g2000cwb.goo glegroups.com.. .
      A SQL Server 2005 DB table has 4 columns namely "ID" (IDENTITY int
      column), "FirstName" (varchar(50)), "LastName" (varchar(50)) & "DOB"
      (datetime). Now when I am trying to add a new row using the following
      INSERT statement:

      sqlDapter.Inser tCommand = New SqlCommand
      sqlDapter.Inser tCommand.Comman dText = "INSERT INTO UserDetailss
      VALUES('bobby', 'simpson','" & Now() & "')"
      sqlDapter.Inser tCommand.Connec tion = sqlConn
      sqlDapter.Updat e(dSet, "UserDetail s")
      'Response.Write ("INSERT INTO UserDetailss VALUES('bobby', 'simpson','" &
      Now() & "')"

      the following error gets generated pointing to the Update line:

      The conversion of a char data type to a datetime data type resulted in
      an out-of-range datetime value.

      I even tried using the different DateTime Format functions but none of
      them work. WHere am I going wrong?

      Thanks

      Arpan

      Comment

      • Juan T. Llibre

        #4
        Re: Insert DateTime Value In DB Table?

        Is the date format whch you are trying to insert the same
        format as your SQL Server's default date format ?




        Juan T. Llibre, asp.net MVP
        aspnetfaq.com : http://www.aspnetfaq.com/
        asp.net faq : http://asp.net.do/faq/
        foros de asp.net, en español : http://asp.net.do/foros/
        =============== =============== =====
        "Arpan" <arpan_de@hotma il.comwrote in message
        news:1155959144 .074095.271140@ 74g2000cwt.goog legroups.com...
        >DateTime.Now is a DateTime value, not a string. Try using
        >DateTime.Now.T oString()
        >
        Kevin, DateTime.Now.To String() still generates the same out-of-range
        error & why wouldn't it? The data type of the column named "DOB" in the
        DB table (& hence in the DataSet as well) is "datetime" which means SQL
        Server is expecting a datetime record in that column; so converting it
        to string - how will that work?
        >
        Please correct me if I am wrong.
        >
        Thanks,
        >
        Regards,
        >
        Arpan
        >
        Kevin Spencer wrote:
        >DateTime.Now is a DateTime value, not a string. Try using
        >DateTime.Now.T oString()
        >>
        >--
        >HTH,
        >>
        >Kevin Spencer
        >Microsoft MVP
        >Chicken Salad Surgery
        >>
        >Orange you bland I stopped splaying bananas?
        >>
        >>
        >"Arpan" <arpan_de@hotma il.comwrote in message
        >news:115582231 5.014394.128380 @b28g2000cwb.go oglegroups.com. ..
        >A SQL Server 2005 DB table has 4 columns namely "ID" (IDENTITY int
        column), "FirstName" (varchar(50)), "LastName" (varchar(50)) & "DOB"
        (datetime). Now when I am trying to add a new row using the following
        INSERT statement:
        >
        sqlDapter.Inser tCommand = New SqlCommand
        sqlDapter.Inser tCommand.Comman dText = "INSERT INTO UserDetailss
        VALUES('bobby', 'simpson','" & Now() & "')"
        sqlDapter.Inser tCommand.Connec tion = sqlConn
        sqlDapter.Updat e(dSet, "UserDetail s")
        'Response.Write ("INSERT INTO UserDetailss VALUES('bobby', 'simpson','" &
        Now() & "')"
        >
        the following error gets generated pointing to the Update line:
        >
        The conversion of a char data type to a datetime data type resulted in
        an out-of-range datetime value.
        >
        I even tried using the different DateTime Format functions but none of
        them work. WHere am I going wrong?
        >
        Thanks
        >
        Arpan
        >
        >

        Comment

        • Arpan

          #5
          Re: Insert DateTime Value In DB Table?

          Is the date format whch you are trying to insert the same
          format as your SQL Server's default date format ?
          Juan, the datetime records already present in SQL Server look like
          this:

          19/08/2006 11:17:45 AM

          & when I do a

          Response.Write( Now())

          the output is exactly the same i.e.

          19/08/2006 11:17:45 AM

          So I guess they are the same, aren't they?

          Thanks,

          Regards,

          Arpan

          Juan T. Llibre wrote:
          Is the date format whch you are trying to insert the same
          format as your SQL Server's default date format ?
          >
          >
          >
          >
          Juan T. Llibre, asp.net MVP
          aspnetfaq.com : http://www.aspnetfaq.com/
          asp.net faq : http://asp.net.do/faq/
          foros de asp.net, en español : http://asp.net.do/foros/
          =============== =============== =====
          "Arpan" <arpan_de@hotma il.comwrote in message
          news:1155959144 .074095.271140@ 74g2000cwt.goog legroups.com...
          DateTime.Now is a DateTime value, not a string. Try using
          DateTime.Now.To String()
          Kevin, DateTime.Now.To String() still generates the same out-of-range
          error & why wouldn't it? The data type of the column named "DOB" in the
          DB table (& hence in the DataSet as well) is "datetime" which means SQL
          Server is expecting a datetime record in that column; so converting it
          to string - how will that work?

          Please correct me if I am wrong.

          Thanks,

          Regards,

          Arpan

          Kevin Spencer wrote:
          DateTime.Now is a DateTime value, not a string. Try using
          DateTime.Now.To String()
          >
          --
          HTH,
          >
          Kevin Spencer
          Microsoft MVP
          Chicken Salad Surgery
          >
          Orange you bland I stopped splaying bananas?
          >
          >
          "Arpan" <arpan_de@hotma il.comwrote in message
          news:1155822315 .014394.128380@ b28g2000cwb.goo glegroups.com.. .
          A SQL Server 2005 DB table has 4 columns namely "ID" (IDENTITY int
          column), "FirstName" (varchar(50)), "LastName" (varchar(50)) & "DOB"
          (datetime). Now when I am trying to add a new row using the following
          INSERT statement:

          sqlDapter.Inser tCommand = New SqlCommand
          sqlDapter.Inser tCommand.Comman dText = "INSERT INTO UserDetailss
          VALUES('bobby', 'simpson','" & Now() & "')"
          sqlDapter.Inser tCommand.Connec tion = sqlConn
          sqlDapter.Updat e(dSet, "UserDetail s")
          'Response.Write ("INSERT INTO UserDetailss VALUES('bobby', 'simpson','" &
          Now() & "')"

          the following error gets generated pointing to the Update line:

          The conversion of a char data type to a datetime data type resulted in
          an out-of-range datetime value.

          I even tried using the different DateTime Format functions but none of
          them work. WHere am I going wrong?

          Thanks

          Arpan

          Comment

          Working...