Search code examples
delphifiredac

Why is this FireDAC SQL Server query with parameters failing?


This is my first time doing a query with parameters. (Using Delphi Seattle and FireDAC in SQL Server)

(I'm planning on using DML once I get this working.)

Why am I getting this error:

[FireDAC][Phys][ODBC][Microsoft][SQL Server Native Client 11.0]
[SQL Server]Incorrect syntax near ':'.

with this query:

procedure TForm2.Button1Click(Sender: TObject);
var
  FDParam: TFDParam;
begin
  FDQuery1.SQL.Text := 'CREATE TABLE TestTable (Column1 Int)';
  FDQuery1.ExecSQL;

  FDQuery1.SQL.Text := 'INSERT INTO TestTable (Column1) VALUES (111)';
  FDQuery1.ExecSQL;  // works fine

  FDParam := FDQuery1.Params.Add;
  FDParam.Name := 'Column1';
  FDParam.DataType := ftInteger;
  FDParam.Paramtype := ptInput;

  FDQuery1.SQL.Text := 'INSERT INTO TestTable (Column1) VALUES(:Column1)' ;
  FDQuery1.ParamByName('Column1').AsInteger := 222;
  FDQuery1.ExecSQL;  // FAILS 
end;

Solution

  • Ken and Johan: thanks for your comments.

    Someone here had set the connection's ResourceOptions.ParamCreate and ParamExpand to false.

    Overriding that in the FDQuery eliminated the problem.

    Thank you again.