执行更新查询时查询表达式中的语法错误(缺少运算符)

时间:2022-03-06 15:36:59

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 :

我似乎有一个更新查询的问题,我正在尝试使用它来使用Delphi XE2更新用户在MS Access数据库中的当前详细信息。我之前问了一个问题并得到了保留字的帮助,但现在我似乎又遇到了这个查询的错误。错误是:

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.

DB是ADOQuery组件,ID是数据库中的主键,对每条记录都是唯一的。 TUser是我作为对象创建的类。

Please Help me sort this out.

请帮我解决这个问题。

1 个解决方案

#1


3  

please use Comma in SQL add lines:

请在SQL添加行中使用逗号:

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');

#1


3  

please use Comma in SQL add lines:

请在SQL添加行中使用逗号:

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');