I am using a dataset. I have an Adapter table called PackageTableAdapter that contains the InsertPackage method .
INSERT INTO [dbo].[Packages] ([UserID], [Name]) VALUES (@UserID, @Name)
//Return the PackageID value for the newly created record...
SELECT SCOPE_IDENTITY()
This table adapter is used by a mid-level class with the code below:
private PackagesTableAdapter _packagesTableAdapter = null;
protected PackagesTableAdapter Adapter
{
get
{
if (_packagesTableAdapter == null)
_packagesTableAdapter = new PackagesTableAdapter();
return _packagesTableAdapter;
}
}
public bool AddPackage(string PackageName)
{
Album.PackagesDataTable packages = new AlbumCongo.PackagesDataTable();
Album.PackagesRow package = packages.NewPackagesRow();
package.Name = PackageName;
packages.AddPackagesRow(package);
int rowsAffected = Adapter.Update(packages);
return rowsAffected == 1;
}
How can I capture the primary key of a newly created package (the one that should have been returned by the SELECT SCOPE_IDENTITY () statement )?
EDIT
Instead of returning a bool value, I would like to return a custom object that contains both a bool value and an int representing the identifier of the newly created row.
Thanks for the help.
source
share