To retrieve UID after update

nicorvp

Member
Joined
May 3, 2009
Messages
24
Location
Italy
Programming Experience
5-10
Hi,
if I have a datatable with an auto-increment primarykey column, which is the best way to retrieve back the primarykey of a new row after an update of the db?
It would be nice if TableAdapters.Update could give back updated row but it seems to be not possible.
Thanks
 
The answer to your question is heavily dependent on the database you're using. Please always provide all the relevant information when posting. What database you're using is almost always relevant when questions involve the database.
 
Thanks for your reply
I'm using Access
I that case, what you're asking for can't be done. You have no choice but to requery the database to get the new data. If you're the only one accessing the database and you only inserted one record then you can simply query the database for the last ID and plug that into your app. If their are multiple users or you inserted multiple rows then you pretty much to discard all your data and retrieve it all again.

This is an example of why Access is not a "real" database. It does a job and has its advantages but a real server-based database, e.g. SQL Server Express, would allow you to retrieve the new ID as part of the insert with no additional code.
 
Back
Top