Salvador
Salvador

Reputation: 16472

AdoQuery Error using parameters

I need update a field value , increasing the old value. something like ths

UPDATE MYTABLE SET FIELD1=FIELD1+VALUE WHERE ....

but when run the next code i have this error

Parameter object is improperly defined. Inconsistent or incomplete information was provided

this is my code

AdoQuery:=TADOQuery.Create(nil);
    try
        AdoQuery.Connection:=FAdoConnection;
        AdoQuery.Active:=False;
        AdoQuery.Parameters.CreateParameter('RECON',ftFloat,pdInput,SizeOf(Double),d1);
        AdoQuery.Parameters.CreateParameter('NUM',ftInteger,pdInput,SizeOf(Integer),Trans);
        AdoQuery.Parameters.CreateParameter('LIN'   ,ftInteger,pdInput,SizeOf(Integer),Lin);
        AdoQuery.SQL.Clear;
        AdoQuery.SQL.Add('UPDATE DIPTT SET VALRECON=:RECON+VALRECON WHERE NUM=:NUM AND LIN=:LIN');
        AdoQuery.Prepared:=True;
        AdoQuery.ExecSQL;
    finally
        if AdoQuery.Active then AdoQuery.Close;
        AdoQuery.Free;
    end;

i tried multiples combinations

1)

    AdoQuery.SQL.Add('UPDATE DIPTT SET VALRECON=VALRECON+:RECON WHERE NUM=:NUM AND LIN=:LIN');

2)

        AdoQuery.SQL.Add('UPDATE DIPTT SET VALRECON=(VALRECON)+:RECON WHERE NUM=:NUM AND LIN=:LIN');

Only when i tried this it works. (obviously this is not a valid option, but show me where the problem is)

        AdoQuery.SQL.Add('UPDATE DIPTT SET VALRECON=:RECON WHERE NUM=:NUM AND LIN=:LIN');

How can rewrite this sentece?

Any clues?

Upvotes: 1

Views: 4921

Answers (1)

robsoft
robsoft

Reputation: 5585

Quick guess (nothingto hand right now to play with this) but try putting the parameter in brackets thus;

UPDATE DIPTT SET VALRECON=(:RECON)+(VALRECON) WHERE NUM=:NUM etc

Failing that, your best route might be to construct the SQL statement dynamically for that part eg

FSQL:='UPDATE DIPTT SET VALRECON=VALRECON+' + IntToStr(d1) + 
      ' WHERE NUM=:NUM etc';
AdoQuery.SQL.Text:=FSQL;

then set your Num parameter values (etc) as before

Upvotes: 2

Related Questions