Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread How to retrieve an autoinc value after an INSERT
Sun, May 25 2008 9:50 AMPermanent Link

"M.E."
After an ExecSQL to insert a record, it seems the query becomes inactive and
I'm not being able to retrieve the value assigned to the autoinc field.
This is what I'm doing:

         With QueryTemp do
           begin
             SQL.Clear;
             SQL.Add('INSERT INTO "Items" (Cod)');
             SQL.Add('VALUES (' + QuotedStr(Orc) + ')');
             SQL.Add('COMMIT FLUSH');
             ExecSQL;
             Id := FieldByName('Id').AsInteger; // ERROR HERE
             Close;
           end;

What can I do to retrieve the Id value?
Thanks
Marcio


Sun, May 25 2008 1:01 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Marcio,

<< After an ExecSQL to insert a record, it seems the query becomes inactive
and I'm not being able to retrieve the value assigned to the autoinc field.
This is what I'm doing: >>

Use a parameterized INSERT like this:

         With QueryTemp do
           begin
             SQL.Clear;
             SQL.Add('INSERT INTO "Items" (ID, Cod)');
             SQL.Add('VALUES (:ID, ' + QuotedStr(Orc) + ')');
             SQL.Add('COMMIT FLUSH');
             Prepare;
             ParamByName('ID').ParamType:=ptInputOutput;
             ExecSQL;
             Id := ParamByName('ID').AsInteger;
           end;

--
Tim Young
Elevate Software
www.elevatesoft.com

Sun, May 25 2008 1:30 PMPermanent Link

"M.E."
Thanks, Tim, but I'm getting an "Undeclared identifier: ParamType" error at
that line. Do I need to include some special unit at the Uses?
Marcio

"Tim Young [Elevate Software]" <timyoung@elevatesoft.com> escreveu:
>
> Use a parameterized INSERT like this:
(...)
>              ParamByName('ID').ParamType:=ptInputOutput;
(...)

Sun, May 25 2008 7:21 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Marcio,

<< Thanks, Tim, but I'm getting an "Undeclared identifier: ParamType" error
at that line. Do I need to include some special unit at the Uses? >>

You need the DB unit in the USES clause in addition to the edbcomps unit.

--
Tim Young
Elevate Software
www.elevatesoft.com

Sun, May 25 2008 8:48 PMPermanent Link

"M.E."
I forgot to say I am using Dbisam 4, not EDB.
DB and DBIsamTb units are already there. Frown
Marcio


"Tim Young [Elevate Software]" <timyoung@elevatesoft.com> escreveu:
>
> You need the DB unit in the USES clause in addition to the edbcomps unit.
>

Sun, May 25 2008 9:39 PMPermanent Link

"M.E."
Tim, thanks anyway, I found a workaround.
M.

"Tim Young [Elevate Software]" <timyoung@elevatesoft.com> escreveu:

> You need the DB unit in the USES clause in addition to the edbcomps unit.

Image