|
 |
asp_databases thread: How to get the Primary ID number of the newly added record?
Message #1 by "Philip.Ware" <Philip.Ware@e...> on Fri, 19 May 2000 10:46:11 +0100
|
|
Hi,
How can I obtain the current ID (autonumber) when creating a new record?
I have something like...
rs.addnew
rs.fields("blar") = "stuff"
rs.update
newrecord = rs.fields("Id")
but each time newrecord is always 0.
To get the new record number I have to close the recordset, and then reopen
it, a grab the highest ID number - which is a bit crap really...
How can I get the ID autonumber when adding a new record - or just after I
have updated it.
Thanks,
Phil.
Message #2 by =?iso-8859-1?Q?=C1rni_B=2E_Halld=F3rsson?= <abh@t...> on Fri, 19 May 2000 11:10:47 -0000
|
|
I would use the sql syntax "select max(id) as maxid from <tablename>",
That
will return the highest id number.
Arni Halldorsson
abh@t...
-----Original Message-----
From: Philip.Ware
Sent: 19. ma=ED 2000 09:46
To: ASP Databases
Subject: [asp_databases] How to get the Primary ID number of the newly
added record?
Hi,
How can I obtain the current ID (autonumber) when creating a new
record?
I have something like...
rs.addnew
rs.fields("blar") =3D "stuff"
rs.update
newrecord =3D rs.fields("Id")
but each time newrecord is always 0.
To get the new record number I have to close the recordset, and then
reopen
it, a grab the highest ID number - which is a bit crap really...
How can I get the ID autonumber when adding a new record - or just
after I
have updated it.
Thanks,
Phil.
Message #3 by "Philip.Ware" <Philip.Ware@e...> on Fri, 19 May 2000 12:33:35 +0100
|
|
Yes but somebody might have already inserted another record between the
time
I do a
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.
But I cant find a why of returning the new records ID number at the
time of
the rs.update method.
Phil.
> -----Original Message-----
> From: =C1rni B. Halld=F3rsson
> Sent: 19 May 2000 12:11
> To: ASP Databases
> Subject: [asp_databases] RE: How to get the Primary ID number of the
> newly added record?
>
>
> I would use the sql syntax "select max(id) as maxid from
> <tablename>", That
> will return the highest id number.
>
> Arni Halldorsson
> abh@t...
>
> -----Original Message-----
> From: Philip.Ware
> Sent: 19. ma=ED 2000 09:46
> To: ASP Databases
> Subject: [asp_databases] How to get the Primary ID number of the
newly
> added record?
>
>
> Hi,
>
> How can I obtain the current ID (autonumber) when creating a
> new record?
>
> I have something like...
>
> rs.addnew
> rs.fields("blar") =3D "stuff"
> rs.update
>
> newrecord =3D rs.fields("Id")
>
> but each time newrecord is always 0.
>
> To get the new record number I have to close the recordset,
> and then reopen
> it, a grab the highest ID number - which is a bit crap really...
>
> How can I get the ID autonumber when adding a new record - or
> just after I
> have updated it.
>
> Thanks,
> Phil.
Message #4 by Mark Everest <Mark.Everest@t...> on Fri, 19 May 2000 12:36:36 +0100
|
|
I have not tried this, but at the point you do an AddNew, is the new ID
available form the field, before you to the update?
-----Original Message-----
From: Philip.Ware
Sent: 19 May 2000 10:46
To: ASP Databases
Subject: [asp_databases] How to get the Primary ID number of the newly
added record?
Hi,
How can I obtain the current ID (autonumber) when creating a new record?
I have something like...
rs.addnew
rs.fields("blar") = "stuff"
rs.update
newrecord = rs.fields("Id")
but each time newrecord is always 0.
To get the new record number I have to close the recordset, and then reopen
it, a grab the highest ID number - which is a bit crap really...
How can I get the ID autonumber when adding a new record - or just after I
have updated it.
Thanks,
Phil.
Message #5 by "Philip.Ware" <Philip.Ware@e...> on Fri, 19 May 2000 13:15:00 +0100
|
|
Always returns Null...
:(
> -----Original Message-----
> From: Mark Everest
> Sent: 19 May 2000 12:37
> To: ASP Databases
> Subject: [asp_databases] RE: How to get the Primary ID number of the
> newly added record?
>
>
> I have not tried this, but at the point you do an AddNew, is
> the new ID
> available form the field, before you to the update?
>
>
>
> -----Original Message-----
> From: Philip.Ware
> Sent: 19 May 2000 10:46
> To: ASP Databases
> Subject: [asp_databases] How to get the Primary ID number of the newly
> added record?
>
>
> Hi,
>
> How can I obtain the current ID (autonumber) when creating a
> new record?
>
> I have something like...
>
> rs.addnew
> rs.fields("blar") = "stuff"
> rs.update
>
> newrecord = rs.fields("Id")
>
> but each time newrecord is always 0.
>
> To get the new record number I have to close the recordset,
> and then reopen
> it, a grab the highest ID number - which is a bit crap really...
>
> How can I get the ID autonumber when adding a new record - or
> just after I
> have updated it.
>
> Thanks,
> Phil.
>
Message #6 by "Robert Larsson" <robert.l@m...> on Fri, 19 May 2000 14:04:13 -0700
|
|
After You've made your
rs.Update
do a:
id = rs("id")
rs.Close
In that order and You'll get the latest added autonumber. Instead of
repoening the database and use a MAX select query.
Cheers,
Robert Larsson!
----- Original Message -----
From: "Mark Everest" <Mark.Everest@t...>
To: "ASP Databases" <asp_databases@p...>
Sent: Friday, May 19, 2000 4:36 AM
Subject: [asp_databases] RE: How to get the Primary ID number of the newly
added record?
> I have not tried this, but at the point you do an AddNew, is the new ID
> available form the field, before you to the update?
>
>
>
> -----Original Message-----
> From: Philip.Ware
> Sent: 19 May 2000 10:46
> To: ASP Databases
> Subject: [asp_databases] How to get the Primary ID number of the newly
> added record?
>
>
> Hi,
>
> How can I obtain the current ID (autonumber) when creating a new record?
>
> I have something like...
>
> rs.addnew
> rs.fields("blar") = "stuff"
> rs.update
>
> newrecord = rs.fields("Id")
>
> but each time newrecord is always 0.
>
> To get the new record number I have to close the recordset, and then
reopen
> it, a grab the highest ID number - which is a bit crap really...
>
> How can I get the ID autonumber when adding a new record - or just after I
> have updated it.
>
> Thanks,
> Phil.
>
> ---
> ASPToday brings the essence of the Wrox Programmer to ProgrammerT
philosophy to you through the Web. Every weekday, this is where you will
find a new, original article by ASP programmers for ASP programmers, for
free. ASPToday at http://www.asptoday.com
> ---
> You are currently subscribed to asp_databases
$subst('Email.Unsub')
>
>
Message #7 by "madhu_m m" <mmadhu_m@h...> on Fri, 19 May 2000 12:22:04 GMT
|
|
hi,
One way of solving the problem is to use a stored procedure to add a new
record, u can use the @@Identity variable to get the id of the new record
added.
Madhu
>From: "Philip.Ware"
>Reply-To: "ASP Databases" <asp_databases@p...>
>To: "ASP Databases" <asp_databases@p...>
>Subject: [asp_databases] RE: How to get the Primary ID number of the
>n ewly added record?
>Date: Fri, 19 May 2000 12:33:35 +0100
>
>Yes but somebody might have already inserted another record between the
>time
>I do a
>
>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.
>
>But I cant find a why of returning the new records ID number at the time of
>the rs.update method.
>
>Phil.
>
> > -----Original Message-----
> > From: Árni B. Halldórsson
> > Sent: 19 May 2000 12:11
> > To: ASP Databases
> > Subject: [asp_databases] RE: How to get the Primary ID number of the
> > newly added record?
> >
> >
> > I would use the sql syntax "select max(id) as maxid from
> > <tablename>", That
> > will return the highest id number.
> >
> > Arni Halldorsson
> > abh@t...
> >
> > -----Original Message-----
> > From: Philip.Ware
> > Sent: 19. maí 2000 09:46
> > To: ASP Databases
> > Subject: [asp_databases] How to get the Primary ID number of the newly
> > added record?
> >
> >
> > Hi,
> >
> > How can I obtain the current ID (autonumber) when creating a
> > new record?
> >
> > I have something like...
> >
> > rs.addnew
> > rs.fields("blar") = "stuff"
> > rs.update
> >
> > newrecord = rs.fields("Id")
> >
> > but each time newrecord is always 0.
> >
> > To get the new record number I have to close the recordset,
> > and then reopen
> > it, a grab the highest ID number - which is a bit crap really...
> >
> > How can I get the ID autonumber when adding a new record - or
> > just after I
> > have updated it.
> >
> > Thanks,
> > Phil.
Message #8 by "Philip.Ware" <Philip.Ware@e...> on Fri, 19 May 2000 13:30:14 +0100
|
|
But this returns Null
Am I opening it right?
Client-Side cursors, optimistic updating. ??
something to do with this?
cheers,
Phil.
> From: Robert Larsson
> rs.Update
> id = rs("id")
> rs.Close
Message #9 by Mark Everest <Mark.Everest@t...> on Fri, 19 May 2000 13:56:07 +0100
|
|
They only way to implement this method is to do the update and then the
select inside a transaction. This iwll stop other users from adding
the
next record before you have committed the current one and checked the
value.
-----Original Message-----
From: Philip.Ware
Sent: 19 May 2000 12:34
To: ASP Databases
Subject: [asp_databases] RE: How to get the Primary ID number of the n
ewly added record?
Yes but somebody might have already inserted another record between the
time
I do a
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.
But I cant find a why of returning the new records ID number at the
time of
the rs.update method.
Phil.
> -----Original Message-----
> From: =C1rni B. Halld=F3rsson
> Sent: 19 May 2000 12:11
> To: ASP Databases
> Subject: [asp_databases] RE: How to get the Primary ID number of the
> newly added record?
>
>
> I would use the sql syntax "select max(id) as maxid from
> <tablename>", That
> will return the highest id number.
>
> Arni Halldorsson
> abh@t...
>
> -----Original Message-----
> From: Philip.Ware
> Sent: 19. ma=ED 2000 09:46
> To: ASP Databases
> Subject: [asp_databases] How to get the Primary ID number of the
newly
> added record?
>
>
> Hi,
>
> How can I obtain the current ID (autonumber) when creating a
> new record?
>
> I have something like...
>
> rs.addnew
> rs.fields("blar") =3D "stuff"
> rs.update
>
> newrecord =3D rs.fields("Id")
>
> but each time newrecord is always 0.
>
> To get the new record number I have to close the recordset,
> and then reopen
> it, a grab the highest ID number - which is a bit crap really...
>
> How can I get the ID autonumber when adding a new record - or
> just after I
> have updated it.
>
> Thanks,
> Phil.
Message #10 by =?iso-8859-1?Q?=C1rni_B=2E_Halld=F3rsson?= <abh@t...> on Fri, 19 May 2000 13:37:06 -0000
|
|
well, maybe not a good idea, but idea :)
application.lock
update
select with max count
application.unlock
How does that sound?
Arni B. Halldorsson
abh@t...
-----Original Message-----
From: Mark Everest
Sent: 19. ma=ED 2000 12:56
To: ASP Databases
Subject: [asp_databases] RE: How to get the Primary ID number of the n
ewly added record?
They only way to implement this method is to do the update and then the
select inside a transaction. This iwll stop other users from adding
=3D
the
next record before you have committed the current one and checked the
=3D
value.
-----Original Message-----
From: Philip.Ware
Sent: 19 May 2000 12:34
To: ASP Databases
Subject: [asp_databases] RE: How to get the Primary ID number of the n
ewly added record?
Yes but somebody might have already inserted another record between the
=3D
time
I do a=3D20
rs.update and
rs.open "Select max(id) as max....."
Basically after the user updates the recordset with a new record I want
=3D
to
post an email with
Record ID #xx was submitted.
But I cant find a why of returning the new records ID number at the =3D
time of
the rs.update method.
Phil.
> -----Original Message-----
> From: =3DC1rni B. Halld=3DF3rsson=3D20
> Sent: 19 May 2000 12:11
> To: ASP Databases
> Subject: [asp_databases] RE: How to get the Primary ID number of the
> newly added record?
>=3D20
>=3D20
> I would use the sql syntax "select max(id) as maxid from=3D20
> <tablename>", That
> will return the highest id number.
>=3D20
> Arni Halldorsson
> abh@t...
>=3D20
> -----Original Message-----
> From: Philip.Ware=3D20
> Sent: 19. ma=3DED 2000 09:46
> To: ASP Databases
> Subject: [asp_databases] How to get the Primary ID number of the =3D
newly
> added record?
>=3D20
>=3D20
> Hi,
>=3D20
> How can I obtain the current ID (autonumber) when creating a=3D20
> new record?
>=3D20
> I have something like...
>=3D20
> rs.addnew
> rs.fields("blar") =3D3D "stuff"
> rs.update
>=3D20
> newrecord =3D3D rs.fields("Id")
>=3D20
> but each time newrecord is always 0.
>=3D20
> To get the new record number I have to close the recordset,=3D20
> and then reopen
> it, a grab the highest ID number - which is a bit crap really...
>=3D20
> How can I get the ID autonumber when adding a new record - or=3D20
> just after I
> have updated it.
>=3D20
> Thanks,
> Phil.
Message #11 by Mark Everest <Mark.Everest@t...> on Fri, 19 May 2000 16:55:48 +0100
|
|
Do you get the feeling that no-one really knows the right answer to this? I
have guessed three times now - God knows if I am right or not!!!!
Anyway, back to the point....
Because I am a nice sort of a chap, I have managed to get the following
working in VB.
This does report the ID field OK.
Dim adoCon As New ADODB.Connection
Dim adoSet As New ADODB.Recordset
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\db1.mdb;Persist Security Info=False"
adoSet.Open "Table1", adoCon, adOpenKeyset, adLockOptimistic, adCmdTable
adoSet.AddNew
MsgBox adoSet.Fields("ID")
adoSet.Fields("Text").Value = "HI"
adoSet.Update
I hope this helps......
Message #12 by "Philip.Ware" <Philip.Ware@e...> on Fri, 19 May 2000 17:04:39 +0100
|
|
Thanks, I will try this later on....
> Because I am a nice sort of a chap, I have managed to get the
> following working in VB.
> This does report the ID field OK.
> Dim adoCon As New ADODB.Connection
> Dim adoSet As New ADODB.Recordset
>
> adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=c:\db1.mdb;Persist Security Info=False"
>
> adoSet.Open "Table1", adoCon, adOpenKeyset,
> adLockOptimistic, adCmdTable
>
> adoSet.AddNew
> MsgBox adoSet.Fields("ID")
> adoSet.Fields("Text").Value = "HI"
> adoSet.Update
Message #13 by "Jessica Chen" <jchen@g...> on Fri, 19 May 2000 12:10:01 -0400
|
|
One of the way i used to solve the problem is create a procedure and put
the
insert and select in an transaction and store in SQL. you can exec the
transaction from the ASP page and let the procedure return the id to the
ASP
page. This way you can guarantee that the lock is hold for you from the t
ime
of date is modified until the end of transaction.
Jessica
-----Original Message-----
From: =C1rni B. Halld=F3rsson
Sent: Friday, May 19, 2000 9:37 AM
To: ASP Databases
Subject: [asp_databases] RE: How to get the Primary ID number of the n
ewly added record?
well, maybe not a good idea, but idea :)
application.lock
update
select with max count
application.unlock
How does that sound?
Arni B. Halldorsson
abh@t...
-----Original Message-----
From: Mark Everest
Sent: 19. ma=ED 2000 12:56
To: ASP Databases
Subject: [asp_databases] RE: How to get the Primary ID number of the n
ewly added record?
They only way to implement this method is to do the update and then the
select inside a transaction. This iwll stop other users from adding =3D
the
next record before you have committed the current one and checked the =3D
value.
-----Original Message-----
From: Philip.Ware
Sent: 19 May 2000 12:34
To: ASP Databases
Subject: [asp_databases] RE: How to get the Primary ID number of the n
ewly added record?
Yes but somebody might have already inserted another record between the =3D
time
I do a=3D20
rs.update and
rs.open "Select max(id) as max....."
Basically after the user updates the recordset with a new record I want =3D
to
post an email with
Record ID #xx was submitted.
But I cant find a why of returning the new records ID number at the =3D
time of
the rs.update method.
Phil.
> -----Original Message-----
> From: =3DC1rni B. Halld=3DF3rsson=3D20
> Sent: 19 May 2000 12:11
> To: ASP Databases
> Subject: [asp_databases] RE: How to get the Primary ID number of the
> newly added record?
>=3D20
>=3D20
> I would use the sql syntax "select max(id) as maxid from=3D20
> <tablename>", That
> will return the highest id number.
>=3D20
> Arni Halldorsson
> abh@t...
>=3D20
> -----Original Message-----
> From: Philip.Ware=3D20
> Sent: 19. ma=3DED 2000 09:46
> To: ASP Databases
> Subject: [asp_databases] How to get the Primary ID number of the =3D
newly
> added record?
>=3D20
>=3D20
> Hi,
>=3D20
> How can I obtain the current ID (autonumber) when creating a=3D20
> new record?
>=3D20
> I have something like...
>=3D20
> rs.addnew
> rs.fields("blar") =3D3D "stuff"
> rs.update
>=3D20
> newrecord =3D3D rs.fields("Id")
>=3D20
> but each time newrecord is always 0.
>=3D20
> To get the new record number I have to close the recordset,=3D20
> and then reopen
> it, a grab the highest ID number - which is a bit crap really...
>=3D20
> How can I get the ID autonumber when adding a new record - or=3D20
> just after I
> have updated it.
>=3D20
> Thanks,
> Phil.
Message #14 by "Philip.Ware" <Philip.Ware@e...> on Fri, 19 May 2000 17:20:14 +0100
|
|
This is very annoying.
To tell you the truth I'm using that awful VB Data Enviroment for my main
tables...
when I just simply do
rs.addnew
new_idval = rs("id")
it works fine in my .asp web version.
I will have to change my VB code to use server side cursors, but I think I
will just create my own instances of the tables and not use the data
enviroment.
I have just recently got rid of the auto-updating controls from the DataEnv,
as the combo boxs can do some weird things!
Hope its all fixed in 7! :)
Thanks all for your help,
Phil.
> -----Original Message-----
> From: Mark Everest
> Sent: 19 May 2000 16:56
> To: ASP Databases
> Subject: [asp_databases] RE: How to get the Primary ID number of the
> newly added record?
>
>
> Do you get the feeling that no-one really knows the right
> answer to this? I
> have guessed three times now - God knows if I am right or not!!!!
>
>
> Anyway, back to the point....
>
> Because I am a nice sort of a chap, I have managed to get the
> following
> working in VB.
>
> This does report the ID field OK.
>
>
>
>
> Dim adoCon As New ADODB.Connection
> Dim adoSet As New ADODB.Recordset
>
> adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=c:\db1.mdb;Persist Security Info=False"
>
> adoSet.Open "Table1", adoCon, adOpenKeyset,
> adLockOptimistic, adCmdTable
>
> adoSet.AddNew
> MsgBox adoSet.Fields("ID")
> adoSet.Fields("Text").Value = "HI"
> adoSet.Update
>
>
>
> I hope this helps......
>
Message #15 by ckoski@w... on Fri, 19 May 2000 14:35:52 -0400
|
|
yes, yes... this is probably the best aproach.... but the only drawback is
that it is SQL Server specific.... @@indentity will return the very last
automatic ID value generated by the system.... you can then return is as a
output parameter in a stored proc or as a field in a recordset...
I used a stored proc for mine... here it is (I have the key cid in my
im_content_index table auto increment):
Create Procedure addlisting
(@time_stamp datatime, @creator_guid char(32))
as
declare @num int
begin tran
insert im_content_index
( created, creator_guid )
values
( @time_stamp, @creator_guid )
select @num = @@IDENTITY
commit tran
return @num
Good luck!
----- Original Message -----
From: "madhu_m m"
To: "ASP Databases" <asp_databases@p...>
Sent: Friday, May 19, 2000 8:22 AM
Subject: [asp_databases] RE: How to get the Primary ID number of the n ewly
added record?
> hi,
> One way of solving the problem is to use a stored procedure to add a new
> record, u can use the @@Identity variable to get the id of the new record
> added.
>
> Madhu
>
>
> >From: "Philip.Ware"
> >Reply-To: "ASP Databases" <asp_databases@p...>
> >To: "ASP Databases" <asp_databases@p...>
> >Subject: [asp_databases] RE: How to get the Primary ID number of the
> >n ewly added record?
> >Date: Fri, 19 May 2000 12:33:35 +0100
> >
> >Yes but somebody might have already inserted another record between the
> >time
> >I do a
> >
> >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.
> >
> >But I cant find a why of returning the new records ID number at the time
of
> >the rs.update method.
> >
> >Phil.
> >
> > > -----Original Message-----
> > > From: Árni B. Halldórsson
> > > Sent: 19 May 2000 12:11
> > > To: ASP Databases
> > > Subject: [asp_databases] RE: How to get the Primary ID number of the
> > > newly added record?
> > >
> > >
> > > I would use the sql syntax "select max(id) as maxid from
> > > <tablename>", That
> > > will return the highest id number.
> > >
> > > Arni Halldorsson
> > > abh@t...
> > >
> > > -----Original Message-----
> > > From: Philip.Ware
> > > Sent: 19. maí 2000 09:46
> > > To: ASP Databases
> > > Subject: [asp_databases] How to get the Primary ID number of the newly
> > > added record?
> > >
> > >
> > > Hi,
> > >
> > > How can I obtain the current ID (autonumber) when creating a
> > > new record?
> > >
> > > I have something like...
> > >
> > > rs.addnew
> > > rs.fields("blar") = "stuff"
> > > rs.update
> > >
> > > newrecord = rs.fields("Id")
> > >
> > > but each time newrecord is always 0.
> > >
> > > To get the new record number I have to close the recordset,
> > > and then reopen
> > > it, a grab the highest ID number - which is a bit crap really...
> > >
> > > How can I get the ID autonumber when adding a new record - or
> > > just after I
> > > have updated it.
> > >
> > > Thanks,
> > > Phil.
>
Message #16 by "Robert Larsson" <robert.l@m...> on Fri, 19 May 2000 23:51:43 +0200
|
|
Have you tried to use the Server-side cursor ?, adOpenReadOnly or something
like that, it's often that who is the problem.
I don't have a complete example right about now, i did make this before and
it worked.
----- Original Message -----
From: "Philip.Ware"
To: "ASP Databases" <asp_databases@p...>
Sent: Friday, May 19, 2000 2:30 PM
Subject: [asp_databases] RE: How to get the Primary ID number of the n ewly
added record?
> But this returns Null
>
> Am I opening it right?
>
> Client-Side cursors, optimistic updating. ??
> something to do with this?
>
> cheers,
> Phil.
>
> > From: Robert Larsson
> > rs.Update
> > id = rs("id")
> > rs.Close
>
>
Message #17 by "Robert Larsson" <robert.l@m...> on Fri, 19 May 2000 23:53:41 +0200
|
|
You don't have to make a new open statement..
do
rs.update
var = rs("id")
rs.close
this way you get the id you just added nomather if anyone else adds one in
the same time. it worked for me.
----- Original Message -----
From: "Mark Everest" <>
To: "ASP Databases" <asp_databases@p...>
Sent: Friday, May 19, 2000 2:56 PM
Subject: [asp_databases] RE: How to get the Primary ID number of the n ewly
added record?
They only way to implement this method is to do the update and then the
select inside a transaction. This iwll stop other users from adding the
next record before you have committed the current one and checked the value.
-----Original Message-----
From: Philip.Ware
Sent: 19 May 2000 12:34
To: ASP Databases
Subject: [asp_databases] RE: How to get the Primary ID number of the n
ewly added record?
Yes but somebody might have already inserted another record between the time
I do a
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.
But I cant find a why of returning the new records ID number at the time of
the rs.update method.
Phil.
> -----Original Message-----
> From: Árni B. Halldórsson
> Sent: 19 May 2000 12:11
> To: ASP Databases
> Subject: [asp_databases] RE: How to get the Primary ID number of the
> newly added record?
>
>
> I would use the sql syntax "select max(id) as maxid from
> <tablename>", That
> will return the highest id number.
>
> Arni Halldorsson
> abh@t...
>
> -----Original Message-----
> From: Philip.Ware
> Sent: 19. maí 2000 09:46
> To: ASP Databases
> Subject: [asp_databases] How to get the Primary ID number of the newly
> added record?
>
>
> Hi,
>
> How can I obtain the current ID (autonumber) when creating a
> new record?
>
> I have something like...
>
> rs.addnew
> rs.fields("blar") = "stuff"
> rs.update
>
> newrecord = rs.fields("Id")
>
> but each time newrecord is always 0.
>
> To get the new record number I have to close the recordset,
> and then reopen
> it, a grab the highest ID number - which is a bit crap really...
>
> How can I get the ID autonumber when adding a new record - or
> just after I
> have updated it.
>
> Thanks,
> Phil.
Message #18 by "Pat Waddington" <paw@s...> on Fri, 19 May 2000 22:40:27 +0100
|
|
I just read the record back in again using a combination of other fields to
identify it.
Pat
----- Original Message -----
From: Árni B. Halldórsson <>
To: ASP Databases <asp_databases@p...>
Sent: Friday, May 19, 2000 12:10 PM
Subject: [asp_databases] RE: How to get the Primary ID number of the newly
added record?
I would use the sql syntax "select max(id) as maxid from <tablename>", That
will return the highest id number.
Arni Halldorsson
abh@t...
-----Original Message-----
From: Philip.Ware
Sent: 19. maí 2000 09:46
To: ASP Databases
Subject: [asp_databases] How to get the Primary ID number of the newly
added record?
Hi,
How can I obtain the current ID (autonumber) when creating a new record?
I have something like...
rs.addnew
rs.fields("blar") = "stuff"
rs.update
newrecord = rs.fields("Id")
but each time newrecord is always 0.
To get the new record number I have to close the recordset, and then reopen
it, a grab the highest ID number - which is a bit crap really...
How can I get the ID autonumber when adding a new record - or just after I
have updated it.
Thanks,
Phil.
|
|
 |