O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Retrieve the Unique ID for a New Record

Problem

You need to insert a record and retrieve its unique ID number, which is generated by the database.

Solution

Use a database stored procedure that returns this information in an output parameter.

Discussion

Many database tables use an ID or a GUID (globally unique identifier) field to uniquely identify records. This field is generated by the database when the record is created, not by the client. However, the client often needs to show this information to the user, and it might serve as a registration number or a confirmation number. To make it easy for the client to retrieve this information, it’s recommended that you use a stored procedure that explicitly returns this information.

For example, the Northwind ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required