Article ID: 170147 - Last Review: July 1, 2004 - Revision: 3.1 How To Retrieve Identity Column After Insert Using RDOThis article was previously published under Q170147 For a Microsoft Visual Basic .NET version of this
article, see
320141
(http://support.microsoft.com/kb/320141/EN-US/
)
. On This PageSUMMARY SQL Server Identity columns automatically increment their
value when a new record is added to the table, which makes them very useful for
a unique primary key. When using RDO, you may want to know what the new value
of the Identity column is after inserting a new record with the RDO
Addnew/Update methods, or with a SQL INSERT statement. SQL Server maintains an environment variable named @@IDENTITY that stores the value of the last Identity column added. This environment variable can be queried several different ways from RDO. MORE INFORMATION The following two code examples demonstrate how the value
of the Identity column is retrieved from the SQL Server Pubs database using
RDO, after a new record is inserted. For testing purpose, a temporary table,
IColTest, is created in Pubs database with one Identity column and one VarChar
column. To create a temporary table and index in SQL Server, select Pubs database, then place the following Create Table T-SQL in the SQL window of ISQL/W and execute it. Example OneThis example uses a stored procedure to insert a row by taking parameters passed from RDO, and then returns the value of @@IDENTITY in a OUTPUT parameter.Task One: Create the Stored Procedure To create this stored procedure, place the following Create Procedure T-SQL in the SQL window of ISQL/W and execute it: Task Two: Create the VB Code
Example TwoYou can also do a Select @@IDENTITY with an OpenResultset after inserting a row without creating a stored procedure on the SQL server.
REFERENCES For additional information of User Connection Designer,
please see the following article in the Microsoft Knowledge Base: 166281
(http://support.microsoft.com/kb/166281/EN-US/
)
: How To Create and Implement a UserConnection (c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Adrian Chiang, Microsoft Corporation | Article Translations
|
Back to the top
