tubisarscev Posted November 29, 2005 Share Posted November 29, 2005 hi, i have an asp page in which multiple users insert new data into an access database. as each user inserts new data, i want them to know the identity number of their record(last record in the database). how can i do this,also what happens if another user inserts data at the same time? do the identity numbers mix? Link to comment Share on other sites More sharing options...
Skemcin Posted November 29, 2005 Share Posted November 29, 2005 hi, i have an asp page in which multiple users insert new data into an access database. as each user inserts new data, i want them to know the identity number of their record(last record in the database). how can i do this,also what happens if another user inserts data at the same time? do the identity numbers mix? There are a couple of ways to go about this and without a sample of your structure I'll be generic:To address you wish to get the ID number of the last record added try this:SELECT TOP 1 IDFROM tablenameORDER BY ID DESC Here are the assumptions associated with this statement.1.) this is run immediately after your initial INSERT statement that creates the record2.) that this is wrapped inside a "transaction" in your ASP code so that nothing else gets done in between the queries.3.) you set a session variable equal to the ID number that is extracted DataConn.BeginTrans(insert your code here)If DataConn.Errors.Count = 0 ThenDataConn.CommitTransElseDataConn..RollbackTransEnd If The second point I make will resolve the other question you have regarding multiple hits to the database.Hope this helps. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now