|
 |
asp_databases thread: RE: How to get the Primary ID number of the n-ewly- added record?
Message #1 by "Charles-E. Nadeau" <charles.nadeau@d...> on Wed, 7 Jun 2000 9:2:42
|
|
On 05/19/00, ""Philip.Ware" <Philip.Ware@e...>" wrote:
> Yes but somebody might have already inserted another record between the
time
I do a
Although it can happen it wouldn't be critical in your case since you are
only interested in the ID on the data you just happend.
rs.update and
rs.open "Select max(id) as max....."
Basically after the user updates the recordset with a new record I want
to
post an email with
Record ID #xx was submitted.
Just isolate your operations inside a transaction (oConn.BeginTrans...
oConn.CommitTrans) and they won't be corrupted by the other concurrent
ones.
Charles
Message #2 by "Ken Schaefer" <ken.s@a...> on Wed, 7 Jun 2000 20:30:36 +1000
|
|
You use a recordset object to insert your data the cursor will be sitting on
the record that you just inserted immediately after calling the .update
method:
objRS("field1") = somevalue
objRS("field2") = someothervalue
objRS.Updaye
intNewPrimaryKeyID = objRS("ID")
objRS.close
set objRS = nothing
There - that wasn't difficult was it?
Otherwise, if you want to use SQL statements, get a the current system date
and time, and insert that into a date field along with the rest of your
data, then select the record back again using the date.
Alternatively, if you are using SQL Server, use @@identity.
Cheers
Ken
----- Original Message -----
From: "Charles-E. Nadeau"
To: "ASP Databases" <asp_databases@p...>
Sent: Wednesday, June 07, 2000 12:00 AM
Subject: [asp_databases] RE: How to get the Primary ID number of the n ewly
added record?
> On 05/19/00, ""Philip.Ware" <Philip.Ware@e...>" wrote:
> > Yes but somebody might have already inserted another record between the
> time
> I do a
>
> Although it can happen it wouldn't be critical in your case since you are
> only interested in the ID on the data you just happend.
>
> rs.update and
>
> rs.open "Select max(id) as max....."
>
> Basically after the user updates the recordset with a new record I want
> to
> post an email with
>
> Record ID #xx was submitted.
>
> Just isolate your operations inside a transaction (oConn.BeginTrans...
> oConn.CommitTrans) and they won't be corrupted by the other concurrent
> ones.
>
> Charles
>
Message #3 by "Philip.Ware" <Philip.Ware@e...> on Wed, 7 Jun 2000 12:00:39 +0100
|
|
> objRS("field2") = someothervalue
> objRS.Updaye
> intNewPrimaryKeyID = objRS("ID")
> objRS.close
Yes, you would think so, but the ID value is returned as empty/null...
It has something to do with the way in which the recordset is opened, the
cursor type.
Phil.
Message #4 by "Ken Schaefer" <ken.s@a...> on Thu, 8 Jun 2000 00:36:43 +1000
|
|
Are you using ServerSide or ClientSide cursors?
Clientside will always give you adOpenStatic, which might not refresh when
you .update...
Have to think about this a bit more...
To be safe though, serverside, dynamic, or serverside keyset should work...
Cheers
Ken
----- Original Message -----
From: "Philip.Ware"
To: "ASP Databases" <asp_databases@p...>
Sent: Wednesday, June 07, 2000 9:00 PM
Subject: [asp_databases] RE: How to get the Primary ID number of the n ewly
added record?
> > objRS("field2") = someothervalue
> > objRS.Updaye
> > intNewPrimaryKeyID = objRS("ID")
> > objRS.close
>
> Yes, you would think so, but the ID value is returned as empty/null...
>
> It has something to do with the way in which the recordset is opened, the
> cursor type.
>
> Phil.
>
|
|
 |