|
-
Jul 7th, 2001, 09:39 AM
#1
Field ID
Im adding a new record to a database using ASP.
The problem is i want to create a new record which i can do fine, and get the ID fields value that is set to autonumber, whats the easiest way to do this?
-
Jul 7th, 2001, 10:07 AM
#2
Good Ol' Platypus
Read the last record's autonumber, increment it, and put it back in. Though it may yell at you since it's an automatic field.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Jul 7th, 2001, 11:05 AM
#3
What if there is another record put in before I can read that field?
-
Jul 7th, 2001, 11:17 AM
#4
Good Ol' Platypus
Then you could get the numberofrecords from the recordset object and increment that to put into your autonumber field.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Jul 7th, 2001, 01:26 PM
#5
That wouldnt work if there are going to be records deleted will it? I could always turn autonumber off.
-
Jul 7th, 2001, 01:50 PM
#6
Fanatic Member
chenko,
Couldn't you just grab the FieldID right after you insert the new record by moving to the last record?
Maybe by combining these procedures into the same sub or function?
Chris
-
Jul 7th, 2001, 02:04 PM
#7
They are in the same sub/function. Right after the .Update I want to get it....
If I add a record, will I have to reopen the recordset to get the new entry?
-
Jul 7th, 2001, 02:08 PM
#8
Fanatic Member
If you already have the recordset open I don't see why you would, maybe I'm wrong. Try moving to the last record after the insert, grab the ID and see if they match.
Chris
-
Jul 8th, 2001, 02:02 AM
#9
Frenzied Member
Are you using Insert statements or are you using the AddNew method of the recordset object?
If your using the later, ADO moves the cursor to the newly added record so just read in the value. If your using Insert statements, then what your describing is an issue.
If you need to add new records AND you need to load them immediately for use, you should use the AddNew method and make sure your recordset is adOpenKeySet or adOpenDynamic and your lock type is not adReadOnly.
oOOo--oOOo
__ /\/\onte96
oOOo--oOOo
Senior Programmer/Analyst
MCP
[email protected]
[email protected]
Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..
-
Jul 8th, 2001, 07:24 AM
#10
I am using the AddNew statment, and im using a Update query after, I have it open for adOpenDynamic 
Cheers
-
Jul 8th, 2001, 12:52 PM
#11
Ok I got back around trying that and it works
Cheers!!
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
|