Results 1 to 5 of 5

Thread: Why doesn't this UPDATE statement work?

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Posts
    15

    Why doesn't this UPDATE statement work?

    This is frustrating, I'm almost sure that the syntax of my UPDATE statement is correct, but I keep getting the Invalid Syntax error.

    Here is the function...

    Private Function ChangePassword(ByVal Password As String, ByVal SalesRep As String) As Boolean

    Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\WebData\OrderRequest\OrderRequest.mdb"
    Dim strSQL As String = "UPDATE Passwords SET Password = " & Chr(39) & Password & Chr(39) & " WHERE SalesReps = " & Chr(39) & SalesRep & Chr(39)

    Dim objConnection As New OleDb.OleDbConnection(strConnection)
    Dim objCommand As New OleDb.OleDbCommand(strSQL, objConnection)
    Dim objTransaction As OleDb.OleDbTransaction

    Try

    objConnection.Open()
    objTransaction = objConnection.BeginTransaction
    objCommand.Transaction = objTransaction
    objCommand.ExecuteNonQuery()
    objTransaction.Commit()
    ChangePassword = True

    Catch oleDBException As Exception

    lblException.Visible = True
    lblException.Text = oleDBException.Message & vbCrLf & oleDBException.Source
    ChangePassword = False

    Finally

    If Not objConnection.State = ConnectionState.Closed Then
    objConnection.Close()
    End If
    objCommand = Nothing
    objConnection = Nothing
    objTransaction = Nothing
    End Try
    End Function

    Thanks,

    Sean

  2. #2

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Posts
    15

    Forgot to add...

    Sorry,

    I should mention that the table name is Passwords and the column name is Password and SalesReps...

    My SQL statement looks like so...

    strSQL = "UPDATE Passwords SET Password = 'blue' WHERE SalesReps = 'Sean'"

  3. #3
    Lively Member
    Join Date
    May 2001
    Location
    Falkenberg, Sweden
    Posts
    76
    Have you tried running the sql-string directly in Access? does it work there?
    ________________________
    Fredrik Klarqvist

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Posts
    15

    Got it...

    I had to add Passwords.Password and it worked fine.

    TableName.FieldName

    Thanks

  5. #5
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    In this bit of coding

    Code:
    SET Password = " & Chr(39) & Password & Chr(39) & " WHERE
    You can do

    Code:
    SET Password = ' " & Password & " ' WHERE
    for the sake of readability.
    Please rate my post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width