How to get IDENTITY value after an INSERT

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Jelly
Posts: 18
Joined: Sat 09 Jul 2005 13:49
Contact:

Post by Jelly » Mon 12 Jun 2006 21:36

Sorry for the late reply.

I have uploaded a sample project, you find it here

It works, if I set the cursortype of msquery1 to ctKeyset... The crDefaultResultSet leeds to an error.

I use Delphi 2006, with SDAC version 3.70.2.28. The SQL Server is either a SQL 2000 server, or a SQL 2005 Server Express. No changes. I use SQLOLEDB.1

Hope this information is enough... If not, just ask... It's probably just a small trick to get the example work.

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Tue 13 Jun 2006 11:40

Please try to modify your INSERT statement as following:
INSERT INTO shippers
(CompanyName, Phone)
VALUES
(:CompanyName, :Phone)
SET :ShipperID = SCOPE_IDENTITY()
If you want your output parameter value to be updated in dataset, it must have the same name as corresponding field.

Jelly
Posts: 18
Joined: Sat 09 Jul 2005 13:49
Contact:

Post by Jelly » Thu 15 Jun 2006 10:59

Hey... That was the point... It looks finde now. Right after the Post, I can read the ID value without the need of a refresh.

Thanks...

Post Reply