|
-
Oct 6th, 2002, 02:45 AM
#1
Thread Starter
Fanatic Member
Last AutoNumber Value
My script inserts data to two tables. Table1 has an autonumber field, which is the primary key. The algo is the ff:
1. Insert record to table1. (thus creating a new value in the autonumber field).
2. Get the new value from the autonumber field of table1 and inserts it to table2.
My problem now is, how can i get the new value in the autonumber field from table1?
On Error GoTo Hell
Hell:
Kill Me
Food For Thought:
- Do not judge a book... if you're not a judge!

-
Oct 6th, 2002, 02:56 AM
#2
Hyperactive Member
If your using SQL server use the following to retrieve the identity number...
Code:
SELECT @@identity FROM tablename
This returns the last autonumber/ identity value...
I am not too sure about Access..
regards
MarkusJ
-
Oct 7th, 2002, 01:05 AM
#3
Thread Starter
Fanatic Member
thank you very much. anybody here who knows it in access? I am planning to use the MAX function of SQL, but considering it is in a networked environment, it will not be safe, because maybe somebody has just inserted a record before i invoke my SQL request against the db, therefore getting the wrong value. pls help...
On Error GoTo Hell
Hell:
Kill Me
Food For Thought:
- Do not judge a book... if you're not a judge!

-
Oct 7th, 2002, 01:43 AM
#4
Lively Member
Hope this may work :
Insert into table2 values ((select max(autonumberfield) from table1),......)
Your attitude determines your altitude!!!
-
Oct 7th, 2002, 02:03 AM
#5
Fanatic Member
if u using SQL Statment then kiran says right..
it not then it's work
rs.open "select * from abc",2,2
rs.addnew
rs.name = "name"
rs.add = "add"
myid = rs.id 'auto generated it
'now second table u can use sql here
insert into 2ndtable values(myid,'abc','bcd')
-
Oct 7th, 2002, 03:14 AM
#6
Thread Starter
Fanatic Member
thank you again! I'll give shahid's code a try. For Kirankumar, that would not still be safe since other user might added another record before the sql statement is invoked. Anyway, thanks guys!
On Error GoTo Hell
Hell:
Kill Me
Food For Thought:
- Do not judge a book... if you're not a judge!

-
Oct 9th, 2002, 07:48 AM
#7
Fanatic Member
but i think that the both code are safe
why bcoz whenever user send any request IIS create an thread id
when one thread compelte then 2nd one applay.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|