insert record in Ms Access database AND retrieve the autonumber (ID)

N

nicholas

I would like to insert a new record in a Ms Access database and retrieve the
newly created ID (autonumber).

I would like to do it in VB.NET for an ASP.NET page. ( no asp)

I found several examples on the net, but most of them just work with
sql-server (@@indentity), or use just asp with includes etc.

Hope someone can help me with a 'working' example...

THX
 
G

Greg Burns

FYI, this only supported with Jet 4 (which means Access 2000 or better).

Sorry, I don't have an example on hand...

Greg
 
N

nicholas

sorry to ask this, but what's FYI ?

THX

Greg Burns said:
FYI, this only supported with Jet 4 (which means Access 2000 or better).

Sorry, I don't have an example on hand...

Greg
 
G

Guest

Depending on your needs, you could just insert the record, then immediately
select max(id) from your table. Of course this assumes you've chosen
'Increment' and not 'Random' for the ID column's 'New Values' attribute.

Also, I would *never* do this anywhere there's a chance that two or more
people might be inserting records at about the same time since you might
select the wrong ID if a record is inserted between the time the first record
is inserted and the time you select max(id). Therefore, this approach is
really only useful is very low use or single-user scenarios.
 
L

Leah

I usually store an 'entered by' column, and with ms access, you can
get the max id where the entered by is the current logged on user.

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top