0

I've updated my TableAdapter's advanced options, so it would Refresh the data table.

I'm looking to retrieve the SCOPE_IDENTITY of the new added row, right after I use TableAdapter.Update.

How can this be achieved?

Thanks!

4

1 回答 1

1

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
于 2012-12-05T09:10:16.300 回答