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

  • Thread starter Thread starter nicholas
  • Start date Start date
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
 
FYI, this only supported with Jet 4 (which means Access 2000 or better).

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

Greg
 
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
 
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.
 
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
 
Back
Top