|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to get the NUMID (primary key) of a new record ?
<i><b>Originally posted by : ALJ (alj@leaweb.org)</b></i><br />I have a DB with a field (NUMID) (autonumber primary key)<br /><br />I add a record in my recordset.<br /><br />How can I get the NUMID of this record ?<br /><br />Thank's<br />ALJ<br />
|
|
#2
|
|||
|
|||
|
<i><b>Originally posted by : Dave Z (dz@dzigns.com)</b></i><br />Personally, I prefer an SQL SELECT statement using some of the other information from the form for assurance but...(and I am not sure of the typical ADO stuff)<br />'connect...<br />'Open a table<br />Set rs = Server.CreateObject("ADODB.Recordset")<br />'and<br />rs.movelast<br />'will get you the last record entered<br /><br /><br />------------<br />ALJ at 4/21/2000 5:51:43 PM<br /><br />I have a DB with a field (NUMID) (autonumber primary key)<br /><br />I add a record in my recordset.<br /><br />How can I get the NUMID of this record ?<br /><br />Thank's<br />ALJ<br />
|
|
#3
|
|||
|
|||
|
<i><b>Originally posted by : AndrewJ (andrewjens@hotmail.com)</b></i><br />rs.movelast will not be reliable in a multiuser environment - someone else may add a record between the time you added and movelast. This is an age-old db problem with only two real solutions:<br />1) as Dave Z suggests - SELECT on a secondary key to find the record just created, or<br />2) Get the ID of the record you want to add before you add it. This is the preferred solution in multiuser databases (however you cannot use an autonumber ID field). The steps are:<br />-start a transaction<br />-lock and get the next ID from an independent lookup table<br />-increment the next ID in the lookup table. unlock<br />-add the record with the new ID<br />-commit the transaction<br />Of course, the ID of the new record is stored in a variable and you can do what you like.<br />Cheers<br /><br />------------<br />Dave Z at 4/23/2000 1:16:04 AM<br /><br />Personally, I prefer an SQL SELECT statement using some of the other information from the form for assurance but...(and I am not sure of the typical ADO stuff)<br />'connect...<br />'Open a table<br />Set rs = Server.CreateObject("ADODB.Recordset")<br />'and<br />rs.movelast<br />'will get you the last record entered<br /><br /><br />------------<br />ALJ at 4/21/2000 5:51:43 PM<br /><br />I have a DB with a field (NUMID) (autonumber primary key)<br /><br />I add a record in my recordset.<br /><br />How can I get the NUMID of this record ?<br /><br />Thank's<br />ALJ<br />
|
![]() |
| Viewing: ASP Free Forums > Programming > ASP Development > How to get the NUMID (primary key) of a new record ? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|