Reputation: 51
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.
Upvotes: 0
Views: 1039
Reputation: 142
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');
Upvotes: 3