开发者

Delphi ADO SQL Syntax Error

I am getting an Syntax Error when processing the following lines of code. Especially on the AQ_Query.Open;

procedure THauptfenster.Button1Click(Sender: TObject);
var
    option: TZahlerArray;
begin
    option := werZahlte;
    AQ_Query.Close;
  AQ_Query.SQL.Clear;
  AQ_Query.SQL.Add('USE wgwgwg;');
  AQ_Query.SQL.Add('INSERT INTO abrechnung ');
  AQ_Query.SQL.Add('(`datum`, `titel`, `betrag`, `waldemar`, `jonas`, `ali`, `ben`)');
  AQ_Query.SQL.Add(' VALUES ');
  AQ_Query.SQL.Add('(:datum, :essen, :betrag, :waldemar, :jonas, :ali, :ben);');
  AQ_Query.Parameters.ParamByName('datum').Value := DateToStr(mcDatum.Date);
  AQ_Query.Parameters.ParamByName('essen').Value := ledTitel.Text;
  AQ_Query.Parameters.ParamByName('betrag').Value := ledPreis.Tex开发者_开发技巧t;
  AQ_Query.Parameters.ParamByName('waldemar').Value := option[0];
  AQ_Query.Parameters.ParamByName('jonas').Value := option[1];
  AQ_Query.Parameters.ParamByName('ali').Value := option[2];
  AQ_Query.Parameters.ParamByName('ben').Value := option[3];
  AQ_Query.Open;
end;

The error:

Delphi ADO SQL Syntax Error

I am using MySQL Delphi 2010.


  1. USE and INSERT are two different SQL commands.
  2. MySQL does not support so called "Batches".

=> you have to call these commands one-by-one


Looks to me like you're using backticks on the third AQ_Query.SQL.Add line, when you need to use normal single quotes.


Use the database in the sql script.

AQ_Query.SQL.Add('INSERT INTO wgwgwg.dbo.abrechnung ');
  AQ_Query.SQL.Add('(`wgwgwg.dbo.abrechnung.datum`, `wgwgwg.dbo.abrechnungtitel`, `wgwgwg.dbo.abrechnungbetrag`, `wgwgwg.dbo.abrechnungwaldemar`, `wgwgwg.dbo.abrechnungjonas`, `wgwgwg.dbo.abrechnungali`, `wgwgwg.dbo.abrechnungben`)');

  AQ_Query.SQL.Add(' VALUES ');

  AQ_Query.SQL.Add('(:datum, :essen, :betrag, :waldemar, :jonas, :ali, :ben);');
  AQ_Query.Parameters.ParamByName('datum').Value := DateToStr(mcDatum.Date);
  AQ_Query.Parameters.ParamByName('essen').Value := ledTitel.Text;
  AQ_Query.Parameters.ParamByName('betrag').Value := ledPreis.Text;
  AQ_Query.Parameters.ParamByName('waldemar').Value := option[0];
  AQ_Query.Parameters.ParamByName('jonas').Value := option[1];
  AQ_Query.Parameters.ParamByName('ali').Value := option[2];
  AQ_Query.Parameters.ParamByName('ben').Value := option[3];

You can also make a new connection to wgwgwg and refer your AQ_Query to the new connection

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜