0
 public void EditUser(string id, string userid, string email, string password)
    {
        try
        {
            _dbConn.Open();

            OleDbCommand updateCmd = new OleDbCommand("UPDATE LOGINS SET Username=?, Password=?, Email=? WHERE ID=?", _dbConn);


            OleDbParameter param1 = new OleDbParameter("Username", userid);
            OleDbParameter param2 = new OleDbParameter("Password", password);
            OleDbParameter param3 = new OleDbParameter("Email", email);
            OleDbParameter param4 = new OleDbParameter("ID", id);

            param1.DbType = DbType.AnsiString;
            param1.Direction = ParameterDirection.Input;
            param2.DbType = DbType.AnsiString;
            param2.Direction = ParameterDirection.Input;
            param3.DbType = DbType.AnsiString;
            param3.Direction = ParameterDirection.Input;
            param4.DbType = DbType.AnsiString;
            param4.Direction = ParameterDirection.Input;

            updateCmd.Parameters.Add(param1);
            updateCmd.Parameters.Add(param2);
            updateCmd.Parameters.Add(param3);
            updateCmd.Parameters.Add(param4);


            int rowsAffected = updateCmd.ExecuteNonQuery();

        }
        catch (Exception excep)
        {

            System.Diagnostics.Trace.WriteLine(excep.Message);
        }
        finally
        {
            if (_dbConn.State == ConnectionState.Open)
                _dbConn.Close();

        }
        return;
    }

I'm using C# and Access 2007, this works perfectly fine when I'm updating a single column. But when I'm trying to update multiple columns at the same time I start to get this exception

"Syntax error in UPDATE statement.".

2 Answers 2

6

Password is a reserved keyword in OLE DB Provider. You need to use it with square brackets like [Password].

As a best practice, change it to non-reserved word.

Also use using statement to dispose your OleDbCommand and OleDbConnection even we can't see it.

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

1 Comment

Thank you, also appreciate the advice on the using statement
0

I agree with Sonar. Password is a reserved keyword in OLE DB Provider.

If you are using multiple tables, To avoid Confusion from reserved keywords -- you must use. select table.[Password] from table;

UPDATE table SET table.[Password]=?

Comments

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.