tags:

views:

554

answers:

1

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?

+2  A: 

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

robsoft
VALRECON=(:RECON)+(VALRECON) works perfect , thanks very much.
Salvador
Great, my pleasure. I think it's the bit in Delphi that works out what (if anything) is a parameter in the SQL statement and so needs binding. I've had to be creative once or twice in the past with both SQL Links (to SQL Server) and dbExpress (to SQL Server) so I guessed it would probably just be a case of making the parser treat your statement as a parameter within an expression, if you see what I mean. :-)
robsoft