Hey everyone,
When creating a new record, I want to get the ID of that record and put it in a session variable. Obviously, it isn't available until the insert is done.
The way I thought of doing it was to do the insert, then immediately do a descending select and grab the first record.
I can see that this is "dangerous" if the db is heavily accessed as there could be another insert before I do the select.
So, I need to lock the table for a moment. I have the following code:
insertCmd.CommandText = strSQL
insertCmd.LockType = 1
insertCmd.Execute
It looks right, but there is no way to actually test it (or is there?) so I have no certainty.
Or does anyone have an idea of a better way of getting the ID of the new record? Steve Davis
hey.you@hahaha.com.au
When creating a new record, I want to get the ID of that record and put it in a session variable. Obviously, it isn't available until the insert is done.
The way I thought of doing it was to do the insert, then immediately do a descending select and grab the first record.
I can see that this is "dangerous" if the db is heavily accessed as there could be another insert before I do the select.
So, I need to lock the table for a moment. I have the following code:
insertCmd.CommandText = strSQL
insertCmd.LockType = 1
insertCmd.Execute
It looks right, but there is no way to actually test it (or is there?) so I have no certainty.
Or does anyone have an idea of a better way of getting the ID of the new record? Steve Davis
hey.you@hahaha.com.au