Page 1 of 1

Can't Prepare sql: Insert into t1 (f3) values (:f3)

Posted: Fri 01 Dec 2017 12:46
by Tom666
On sql server, when executing Insert with parameters, Prepare caused an error,
e.g
uniQuery1.SQL.Text:='Insert into t1 (f3) values (:f3)';
uniQuery1.Prepare;//here error

uniSQL.SQL.Text:='Insert into t1 (f1) values (:f1)';
uniSQL.Prepare;
uniSQL.Execute;//here error.

Re: Can't Prepare sql: Insert into t1 (f3) values (:f3)

Posted: Sat 02 Dec 2017 11:07
by FCS
Hi,

You must assign a value to the parameter before prepare.
Something like this:
uniQuery1.ParamByName('f3').ParamType := ptInput;
uniQuery1.ParamByName('f3').DataType := ftString;
uniQuery1.ParamByName('f3').AsString := 'P';

Re: Can't Prepare sql: Insert into t1 (f3) values (:f3)

Posted: Fri 08 Dec 2017 12:48
by Stellar
UniQuery can automatically request parameter properties (Name, ParamType, DataType, Size, TableTypeName) from the server when the TUniQuery.Prepare method is executed. For this, you should specify True to the special DescribeParams property:

UniQuery1.SpecificOptions.Add('DescribeParams=True');

Alternatively, you can specify the parameters properties manually before executing the Prepare method, as we already advised in the previous post.

More details about the DescribeParams property: https://www.devart.com/sdac/docs/index. ... params.htm