.NETGURU
Retrieving ID after Inserting a record.
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngdata' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Hector Caban
I need to get the ID (from a field) of a new record from a database
after I call the ExecuteNonQuery method. How can I get it with out
opening the dataset again.

Thanks..
Hector Caban=20
A+, Net+, MCP+SB, MCSA, MCSE, MCT, CCNA

Reply to this message...
 
    
TomMallard
@@identity if used properly can return this...

tom mallard
seattle

-----Original Message-----
From: Hector Caban [mailto:Click here to reveal e-mail address]
Sent: Tuesday, June 18, 2002 6:29 AM
To: aspngdata
Subject: [aspngdata] Retrieving ID after Inserting a record.

I need to get the ID (from a field) of a new record from a database
after I call the ExecuteNonQuery method. How can I get it with out
opening the dataset again.

Thanks..
Hector Caban
A+, Net+, MCP+SB, MCSA, MCSE, MCT, CCNA

| [aspngdata] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngdata.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
    
gordon
Q2hlY2sgb3V0IGh0dHA6Ly9kbi55eXl6Lm5ldC9Ebll6QXJ0aWNsZVNob3cuYXNweD9XQT0zDQog
DQpHZncNCkdmd0B5eXl6Lm5ldA0KaHR0cDovL3l5eXoubmV0DQogDQoNCgktLS0tLU9yaWdpbmFs
IE1lc3NhZ2UtLS0tLSANCglGcm9tOiBIZWN0b3IgQ2FiYW4gW21haWx0bzpoZWN0b3JAaGNhYmFu
LmNvbV0gDQoJU2VudDogVHVlIDYvMTgvMjAwMiA4OjI4IEFNIA0KCVRvOiBhc3BuZ2RhdGEgDQoJ
Q2M6IA0KCVN1YmplY3Q6IFthc3BuZ2RhdGFdIFJldHJpZXZpbmcgSUQgYWZ0ZXIgSW5zZXJ0aW5n
IGEgcmVjb3JkLg0KCQ0KCQ0KDQoJSSBuZWVkIHRvIGdldCB0aGUgSUQgKGZyb20gYSBmaWVsZCkg
b2YgYSBuZXcgcmVjb3JkIGZyb20gYSBkYXRhYmFzZQ0KCWFmdGVyIEkgY2FsbCB0aGUgRXhlY3V0
ZU5vblF1ZXJ5IG1ldGhvZC4gSG93IGNhbiBJIGdldCBpdCB3aXRoIG91dA0KCW9wZW5pbmcgdGhl
IGRhdGFzZXQgYWdhaW4uDQoJDQoJVGhhbmtzLi4NCglIZWN0b3IgQ2FiYW4NCglBKywgTmV0Kywg
TUNQK1NCLCBNQ1NBLCBNQ1NFLCBNQ1QsIENDTkENCgkNCgl8IFthc3BuZ2RhdGFdIG1lbWJlciBn
ZndAeXl5ei5uZXQgPSBZT1VSIElEDQoJfCBodHRwOi8vd3d3LmFzcGxpc3RzLmNvbS9hc3BsaXN0
cy9hc3BuZ2RhdGEuYXNwID0gSk9JTi9RVUlUDQoJfCBodHRwOi8vd3d3LmFzcGxpc3RzLmNvbS9z
ZWFyY2ggPSBTRUFSQ0ggQXJjaGl2ZXMNCgkNCgkNCg0K
Reply to this message...
 
    
Hector Caban
I figured it out. I used the SQL "SELECT @@Identity" to get the value.
Thanks anyways ..

-----Original Message-----
From: Hector Caban=20
Sent: Tuesday, June 18, 2002 9:29 AM
To: aspngdata
Subject: [aspngdata] Retrieving ID after Inserting a record.

I need to get the ID (from a field) of a new record from a database
after I call the ExecuteNonQuery method. How can I get it with out
opening the dataset again.

Thanks..
Hector Caban=20
A+, Net+, MCP+SB, MCSA, MCSE, MCT, CCNA

| [aspngdata] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.asplists.com/asplists/aspngdata.asp =3D JOIN/QUIT=20
| http://www.asplists.com/search =3D SEARCH Archives

Reply to this message...
 
    
Andrew Munro
when you first populate the dataset use @@IDENTITY to return the next ID of
the field that will be inserted. @@IDENTITY is only supported by MSSQL by
the way (not .mdb)

andrew

-----Original Message-----
From: Hector Caban [mailto:Click here to reveal e-mail address]
Sent: 18 June 2002 14:29
To: aspngdata
Subject: [aspngdata] Retrieving ID after Inserting a record.

I need to get the ID (from a field) of a new record from a database
after I call the ExecuteNonQuery method. How can I get it with out
opening the dataset again.

Thanks..
Hector Caban
A+, Net+, MCP+SB, MCSA, MCSE, MCT, CCNA

| [aspngdata] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngdata.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
    
Jacob Kruger
Use ExecuteScalar. Returns the first column/first row.

Cheers

Jacob Kruger
Web Developer
Click here to reveal e-mail address

[Original message clipped]

Reply to this message...
 
    
Andy Smith
actually, I've read that Jet 4.0 supports Select @@Identity as well.

__
Andy Smith
Chief Code Monkey

[Original message clipped]

Reply to this message...
 
    
Alex Dresko
The following URL shows IDENTITY to be a key word of Jet 4.0..
Interesting, I didn't know that either. A quick test in Access's query
analyzer proved that it does in fact work.

I suppose it's my own fault for never trying it before, but why hasn't
anyone else brought it up before? :)

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q248738

Alex Dresko
Three Point Oh!

-----Original Message-----
From: Andy Smith [mailto:Click here to reveal e-mail address]
Sent: Tuesday, June 18, 2002 12:01 PM
To: aspngdata
Subject: [aspngdata] RE: Retrieving ID after Inserting a record.

actually, I've read that Jet 4.0 supports Select @@Identity as well.

__
Andy Smith
Chief Code Monkey

[Original message clipped]

| [aspngdata] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngdata.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
    
Ken Schaefer (VIP)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Alex Dresko" <Click here to reveal e-mail address>
Subject: [aspngdata] RE: Retrieving ID after Inserting a record.

: The following URL shows IDENTITY to be a key word of Jet 4.0..
: Interesting, I didn't know that either. A quick test in Access's query
: analyzer proved that it does in fact work.
: http://support.microsoft.com/default.aspx?scid=kb;EN-US;q248738
:
: I suppose it's my own fault for never trying it before, but why hasn't
: anyone else brought it up before? :)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I've had a page on this since mid-2000 (IIRC). Obviously pre .Net
http://www.adopenstatic.com/experiments/fastestautonumber.asp

The original KB article that shows that it is possible is actually Q232144
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q232144

Cheers
Ken

Reply to this message...
 
    
Beattie, Barry

they have but with ASP classic.

I first learnt about @@identity from Ken Sheafer months (years?) ago, others
have also sent list Q's regarding @@identity as a special word.

Barry B

-----Original Message-----
From: Alex Dresko [mailto:Click here to reveal e-mail address]
Sent: Wednesday, 19 June 2002 3:25 AM
To: aspngdata
Subject: [aspngdata] RE: Retrieving ID after Inserting a record.

The following URL shows IDENTITY to be a key word of Jet 4.0..
Interesting, I didn't know that either. A quick test in Access's query
analyzer proved that it does in fact work.

I suppose it's my own fault for never trying it before, but why hasn't
anyone else brought it up before? :)

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q248738

Alex Dresko
Three Point Oh!

-----Original Message-----
From: Andy Smith [mailto:Click here to reveal e-mail address]
Sent: Tuesday, June 18, 2002 12:01 PM
To: aspngdata
Subject: [aspngdata] RE: Retrieving ID after Inserting a record.

actually, I've read that Jet 4.0 supports Select @@Identity as well.

__
Andy Smith
Chief Code Monkey

[Original message clipped]

| [aspngdata] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngdata.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [aspngdata] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngdata.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
 




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification