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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.