title: Dataset: How to capture the primary key value returned by SELECT SCOPE_IDENTITY()?
body: <p>I'm using a dataset. I have a table Adapter called <strong>PackageTableAdapter</strong>, which contains a method called <strong>InsertPackage</strong>.</p>
  
  <pre><code>INSERT INTO [dbo].[Packages] ([UserID], [Name]) VALUES (@UserID, @Name)
  
  //Return the PackageID value for the newly created record...
  SELECT SCOPE_IDENTITY()
  </code></pre>
  
  <p>This table adapter is being used by a middle tier class, with the below code:</p>
  
  <pre><code>private PackagesTableAdapter _packagesTableAdapter = null;
  protected PackagesTableAdapter Adapter
  {
      get
      {
          if (_packagesTableAdapter == null)
              _packagesTableAdapter = new PackagesTableAdapter();
  
          return _packagesTableAdapter;
      }
  }    
  
  public bool AddPackage(string PackageName)
  {
      // Create a new PackageRow instance
      Album.PackagesDataTable packages = new AlbumCongo.PackagesDataTable();
      Album.PackagesRow package = packages.NewPackagesRow();
  
      // Add the new package
      package.Name = PackageName;
      packages.AddPackagesRow(package);
      int rowsAffected = Adapter.Update(packages);       
  
      // Return true if precisely one row was inserted,
      // otherwise false
      return rowsAffected == 1;        
  }
  </code></pre>
  
  <p>How do I capture the primary key of the newly created package (the one that's supposed to returned by the <strong>SELECT SCOPE_IDENTITY()</strong> statement)?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Instead of returning a bool value, I'd like to return a custom object that contains both the bool value and an int representing the ID of the newly created row. </p>
  
  <p>Thanks for helping.</p>