The TableAdapter
will insert the SCOPE_IDENTITY
automatically at the end of the insert statement. The DataRow
contains the newly created identity value after the insert. Just don't set the PK column before you add the row to the table and update it via the TableAdapter
.
Dim daLocation As New LocationTableAdapter() ' the TableAdapter
Dim newLocation = Location.NewLocationRow() ' the new DataRow
newLocation.Name = "Berlin"
Location.AddLocationRow(newLocation)
' now update the DataTable or the DataRow with the TableAdapter
Dim numRowsUpdated As Int32 = daLocation.Update(newLocation)
Dim id As Int32 = newLocation.idLocation ' now the new ID is available