syntax error(missing operator) in query expression in an UPDATE,WHERE SQL STATEMENT.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vbnewbiee
    New Member
    • Oct 2010
    • 4

    syntax error(missing operator) in query expression in an UPDATE,WHERE SQL STATEMENT.

    i am working on this code for my password change option in my vb6 program. with access as backend. but im encountering errorline "syntax error(missing operator) in query expression on my update statement.

    this project is very important to me and i appreciate your future comments. thanks.

    Code:
    Dim cn As New ADODB.Connection
    Dim sql As String
     
    cn.Open "provider=microsoft.jet.OLEDB.4.0;Data source=C:\db1.mdb;Persist security info=true"
     
    sql = "update userlog " & _
         "set passlog= '" & txtpass.Text & "'" & _
         "  where passlog= '" & txtold.Text & "'" &_
         "  where user= '" & Text1.Text & "'"
    cn.Execute (sql)
    cn.Close
    Set cn = Nothing
  • vbnewbiee
    New Member
    • Oct 2010
    • 4

    #2
    pls help!! help me about my prblem.. cant do anything about it.. oh so newbie.. :(

    Comment

    • code green
      Recognized Expert Top Contributor
      • Mar 2007
      • 1726

      #3
      Your query has the wrong structure.
      I also recommend validating and testing the input
      from the form before using in a database query.
      Apart from empty values causing the query to fail,
      there is also the danger of SQL injection.
      Anyway replace the second WHERE with AND
      Code:
      sql = "update userlog " & _ 
           "set passlog= '" & txtpass.Text & "'" & _ 
           "  where passlog= '" & txtold.Text & "'" &_ 
           "  AND user= '" & Text1.Text & "'"

      Comment

      • vbnewbiee
        New Member
        • Oct 2010
        • 4

        #4
        oh that's why... thanks! :)
        gotta ask another, if u wouldn't mind..
        i have been thinking about a transaction log.
        how can that be possible? i mean, if a user edited a ceratin textox, something will execute to give a value that the particular textbox has been edited. :)

        sorry for a bit asking too much. thanks..

        Comment

        • vbnewbiee
          New Member
          • Oct 2010
          • 4

          #5
          sample code. care to look..

          oh that's why... thanks! :)
          gotta ask another, if u wouldn't mind..
          i have been thinking about a transaction log.
          how can that be possible? i mean, if a user edited a certain textbox, something will execute to give a value that the particular textbox has been edited. :)

          sorry for a bit asking too much. thanks..

          Comment

          • code green
            Recognized Expert Top Contributor
            • Mar 2007
            • 1726

            #6
            It depends how important the transaction log is.
            If you want to record previous and new value you are probably going to need another table to store this.

            date previous new ....

            But you could simply add a couple of fields to the current table 'last_updated' 'updated_by' and date stamp when and who it was edited by.

            Comment

            Working...