Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the ID of the Inserted Row 2

Status
Not open for further replies.

acent

Technical User
Feb 17, 2006
247
US
Greetings,

I'm posting this in the Access forum simply because I think this is more a database question than anything else.

I have an intranet website (ASP 2.0/VB.NET) that is "powered" by an Access Database. This website creates and tracks calendar events. Naturally, some of these events are repeating, some are not. And, the boss wants to be able to edit/delete all events that are in a series. No radical new therapy in calendaring.

This leads me to have a master record and then have a number of child records linked to that master record. Unless I'm smoking the powerful stuff, I need to insert the master record, retrieve the ID of that master record and then insert the children. How do I pull this off and be certain the master record id is retrieved?

Thanks in advnace for helping me.

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
try
Code:
currentdb.openrecordset("Select @@IDENTITY")
msgbox RST(0)
 
Thanks for the post.

I s'pose I should have mentioned that I did find that solution, however, what happens I insert a row, another user inserts another row and then I run that query?

Right now, this is a low traffic website so I could probably get away with a rather large margin of error, but I'd rather not have a large margin of error.

Thanks.

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
dont you insert the childrecords right away
then

Code:
dim mydb as database
set mydb=currentdb
mydb.execute "insert into mastertable(field1,field2...) values(value1,value2,....)"
set rst=mydb.openrecordset("Select @@IDENTITY")
ident=rst(0)
"insert into childtable(forginkey,field1,field2...) values(" & ident & ",value1,value2,....)"
 
I did some reading on the @@identity variable. It appears it is a connection global variable and therefore if another user inserts a row, it would not affect the value of @@identity.

Thanks for the help.

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top