1

I'm losing my mind over here.

I'm trying to implement a basic "Forgot your password?" functionality where the user inputs an email address to get a new password. Simple enough, right?

My problem is updating the database, replacing the old password with the new one. I'm working with C# and MS Access.

Here is the update code:

public bool UpdateCustomer(Customer customer){
    try {
        if(con.State == ConnectionState.Closed)
            con.Open();

        string sql = "UPDATE CUSTOMERS SET password=? WHERE userid=?;";

        OleDbCommand cmd = new OleDbCommand(sql, con);
        cmd.Parameters.Add(new OleDbParameters("password", customer.Password));
        cmd.Parameters.Add(new OleDbParameters("userid", customer.UserId));

        cmd.ExecuteNonQuery();

        return true;

    }catch (Exception ex) {

    }finally {
        con.Close();
    }
    return false;
}

The CUSTOMER-table consists of the following columns: UserId, Name, Email, Password and CreatedDate.

While debugging the try-catch throws an exception saying there is a syntax error in the UPDATE-statement. I've done a little trial-and-error replacing password=? with name=? just to see if it will update, and it does infact update the customer name!

The Name and Password columns are, as far as I can see, identical with the data type Text.

What can be the problem?

1 Answer 1

5

PASSWORD is a reserved word in Access.

Try:

UPDATE CUSTOMERS SET [password]=? WHERE userid=?;

(Insert usual comments about storing passwords in plaintext being a really bad idea)

Sign up to request clarification or add additional context in comments.

1 Comment

That was it! Thanks a million! I was going to try renaming the column, but since it's a big project someone else wrote years ago I wanted to keep that as a last resort. Thanks again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.