0

I seem to have a problem with an Update query, I'm trying to use it to update a user's current details in a MS Access database using Delphi XE2. I asked a question previously and got help on the reserved word but now I seem to have another error with this query. The error is :

Syntax error(missing operator) in query expression '?
Surname=?
Username=?
[Password]=?
Grade=?'

That is the error I keep getting Below is the coding I have done:

procedure TUser.UpdateUser(pFirstname, pSurname, pUsername,
  pPassword: String; pGrade, pID: Integer);
var
  sSQL : String;
begin
  opendb('QuizDB.mdb');

  DB.Close;
  DB.SQL.Add('UPDATE tblUsers SET');
  DB.SQL.Add('Firstname=:Firstname');
  DB.SQL.Add('Surname=:Surname');
  DB.SQL.Add('Username=:Username');
  DB.SQL.Add('[Password]=:Password');
  DB.SQL.Add('Grade=:Grade');
  DB.SQL.Add('WHERE ID=:ID');

  Db.Parameters.ParamByName('Firstname').Value := pFirstname;
  Db.Parameters.ParamByName('Surname').Value := pSurname;
  Db.Parameters.ParamByName('Username').Value := pUsername;
  Db.Parameters.ParamByName('Password').Value := pPassword;
  Db.Parameters.ParamByName('Grade').Value := pGrade;
  DB.Parameters.ParamByName('ID').Value := pID;
  DB.ExecSQL;
end;

Where DB is an ADOQuery component, ID is the primary Key in the database and unique to each record. TUser is my class I have created as a object.

Please Help me sort this out.

2
  • Have you seen this: http://dev.mysql.com/doc/refman/5.0/en/update.html and comma delimiter? Commented Oct 9, 2013 at 15:31
  • MySQL is not the same as MS Access. Please use the tags that are appropriate to your question instead of just adding anything that is similar. It helps properly organize the questions, and makes their presence known to people who might help you Commented Oct 9, 2013 at 15:37

1 Answer 1

3

please use Comma in SQL add lines:

DB.Close;
DB.SQL.Add('UPDATE tblUsers SET');
DB.SQL.Add('Firstname=:Firstname,');
DB.SQL.Add('Surname=:Surname,');
DB.SQL.Add('Username=:Username,');
DB.SQL.Add('[Password]=:Password,');
DB.SQL.Add('Grade=:Grade');
DB.SQL.Add('WHERE ID=:ID');
Sign up to request clarification or add additional context in comments.

4 Comments

@Alladinianת I think he got the right answer here. a sample would be nice thought.
@Alladinian thx for warning, but it is the answer... I ll just be care about include a code block for the be a sample of subject..
@kobik thanks for editing. I'll be carefull answering like this kind in future.
@kobik I guess it's fine now so I have removed the comment, thanx for the heads up

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.