vb - sql add record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jamesd0142
    Contributor
    • Sep 2007
    • 471

    vb - sql add record

    i have this:
    [code=text]
    Dim Date1 As String = Format$(Now)
    [/code]
    which gives the value like: "15/02/2008 13:29:41"

    now im using this:
    [code=text]
    con.CommandText = "update users set [passwordchanged] = " & "'" & Date1 & "'" & " where [login] = " & "'" & txtlogchange.Te xt & "'"
    [/code]

    Date1 is being inserted into an sql table, field is smalldatetime(4 ).

    I get the error:

    The statement has been terminated.
    The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value.

    So how do iformat my date so it matches the smalldatetime(4 ) data type in sql server?

    All other values in the table look like:
    "15/02/2008 13:29:41"

    So whats the problem?

    James
  • jamesd0142
    Contributor
    • Sep 2007
    • 471

    #2
    fixed this now:

    i needed to change the sql to:
    [code=text]
    con.CommandText = "update users set [password] = " & "'" & txtpasschange.T ext & "'" & ", [passwordchanged] = " & _
    "convert(varcha r(20), convert(smallda tetime, getdate()), 101)" & _
    " where [login] = " & "'" & txtlogchange.Te xt & "'"
    [/code]

    Line3 has the change^

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      You might need to format the date before processing .

      Comment

      • jamesd0142
        Contributor
        • Sep 2007
        • 471

        #4
        Originally posted by debasisdas
        You might need to format the date before processing .
        Yes once again debasisdas you where correct as you can see from the above post.

        I had to convert it to smalldate before adding to the database (line3)

        James

        Comment

        Working...