|
-
Mar 20th, 2002, 09:50 AM
#1
Thread Starter
Hyperactive Member
obtaining record ID
I am using ASP (with VBScript) to work with an Access database. I want to create a record, and then immediately obtain the auto-generated ID field for that record. I tried something like this:
rs.Open etc...
rs.AddNew
rs("name") = "spandex"
rs.update
recordid = rs("ID")
However, this doesn't work. It doesn't give me a value at all.
How can I do this?
-
Mar 20th, 2002, 10:33 AM
#2
Hyperactive Member
What type of cursor are you using? You need to make sure it's adOpenKeyset.
--
AS
-
Mar 20th, 2002, 01:00 PM
#3
Thread Starter
Hyperactive Member
Well, I was not using that cursor. However, I still don't know how to go aout solving this. My code is as follows:
Code:
rs.Open Query,cn,adOpenKeySet,adLockOptimistic
rs.AddNew
rs("PostDate") = Date
eid = rs("ID")
rs.Update
I am trying to get the right value for eid, but I am always just getting a value of 0.
What am I doing wrong?
-
Mar 20th, 2002, 02:10 PM
#4
Hyperactive Member
That's because you're trying to assign the value *before* you have used the update method.
Try this :
Code:
rs.Open Query,cn,adOpenKeySet,adLockOptimistic
rs.AddNew
rs("PostDate") = Date
rs.Update
eid = rs("ID")
--
AS
-
Mar 20th, 2002, 03:15 PM
#5
Thread Starter
Hyperactive Member
I've already tried that, doesn't work either.
Mayber some other part of my code is wrong. Could you perhaps test it with your own code, and see if it works for you?
Thanks a lot for the help.
-
Mar 21st, 2002, 03:22 AM
#6
Hyperactive Member
I've used it hundreds of times and never had a problem. You'll have to double check everything like the Access DB field is definitely set to autonumber, variable spellings etc. etc.
Also, are you actually getting a 0 (zero) back or nothing at all?
If you still get no success, post all your code and Ill see if I can spot anything.
--
AS
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
|