title: Retrieve identity value from inserted record's primary key
body: <p>i cannot retrieve the new identity value from an inserted record(via DataAdapter.Update) in my DataRow.</p>
  
  <p>I'm using a strong typed Dataset as DAL. The table i want to update is joinded with other tables in the SelectCommand, hence the designer cannot automatically generate the insert-/update-/delete-commands and also it cannot "Refresh the DataTable" automatically(s. <a href="http://msdn.microsoft.com/de-de/library/dex7k4dw%28v=VS.100%29.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/de-de/library/dex7k4dw%28v=VS.100%29.aspx</a>).</p>
  
  <p>I've tried to set AutoIncrement=true/false on the primary-key's DataColumn but the result is the same: last MAX-ID+1 instead of the actual ID the database generated(SQL-Server 2005 EP; pk datatype:int, Is identity:yes, Identity Increment:1).</p>
  
  <p>This will be the wrong value f.e if another instance of the application inserted a record that the first instance yet not knows and therefore generates an ID that already exists.</p>
  
  <p>To retrieve the new identity from db i've appended following to my insert-command's CommandText:</p>
  
  <pre><code>;SELECT CAST (SCOPE_IDENTITY() AS int) AS newIdRMA 
  </code></pre>
  
  <p>Also i've tried to add an Output-Parameter to it's parameter-collection:
  <img src="https://i.stack.imgur.com/QDxva.jpg" alt="enter image description here"></p>
  
  <p>This is part of my code that updates the database and sets the new ID(that doesn't work):</p>
  
  <pre><code> Me.dsRMA.RMA.AddRMARow(newRMA) ' adding new row to the (strong typed) DataTable ' 
   numRowsUpdated = daRMA.Update(Me.dsRMA.RMA) ' update via DataAdapter and insert the new record in DB '
   DirectCast(Page, Services).IdRma = newRMA.IdRMA ' this is not the actual value from DB but old Max-ID +1 '
  </code></pre>
  
  <p>Edit:</p>
  
  <p>this is a screenshot of my TableAdapter's InsertCommand and it's parameter-collection:
  <img src="https://i.stack.imgur.com/cEkxn.jpg" alt="enter image description here"></p>
  
  <p>Thanks in advance.</p>