Retrieve the Unique ID for a New Record in a DataSet

Problem

When you perform an update with the DataAdapter, you want the ID numbers for newly added records to be inserted into the DataSet.

Solution

Use a database stored procedure that returns this information in an output parameter, and map the parameter to the appropriate column.

Discussion

Recipe Retrieve the Unique ID for a New Record demonstrates how to return unique ID information with a stored procedure and configure the ADO.NET database command accordingly. This recipe shows how you can use this command with a DataSet so that the retrieved ID information is applied automatically to the appropriate field in the DataSet.

First you must map the parameters in the command to the fields in the

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.