Nikola
Nikola

Reputation: 512

UPDATE-syntax not working with all columns

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?

Upvotes: 1

Views: 77

Answers (1)

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239654

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)

Upvotes: 5

Related Questions