Page 1 of 1

No return of identity when using INSERT sql on TMSQuery.

Posted: Mon 07 Feb 2005 20:29
by Guest
How can I get the value of the identity column to my TMSQuery dataset after an insert ?
I'm using the TMSQuery component with an insert sql (generated).
(when I remove the insert sql and let SDAC do it automatically it works fine)

I also tried the returnparams and queryidentity options, but that did not help.

SDAC trial version 3.50.0.11 ( win32 delphi 2005 ) Sql2000

CREATE TABLE [dbo].[parts] (
[part] [int] IDENTITY (1, 1) NOT NULL ,
[description] [varchar] (100) NOT NULL
) ON [PRIMARY]
GO

TMSQuery : Select = select part, description from parts

TMSQuery : insert sql = INSERT INTO parts (description) VALUES (:2)
SET :1 = SCOPE_IDENTITY()

Posted: Tue 08 Feb 2005 16:17
by Ikar
In this case you need to write BeforeUpdateExecute handler and set in it ParamType := ptInputOutput for corresponding parameter.

Posted: Tue 08 Feb 2005 18:29
by Guest
Thanks for the help, it works.