Get the primary key of a new record

I have several child tables that have a foreign key for the parent table.

How to add a record to the parent table and get the primary key of this record so that I can then enter rows in the child tables that point to the record in the parent table?

I am doing this in an MS Access database from a C # application.

+6
c # database ms-access primary-key
source share
4 answers

Access 2000 or later supports the @@ IDENTITY property to get the value of the Autonumber field after INSERT. ( msdn )

Edit: This is a link to a similar article for .NET 3.5

+5
source share
+4
source share

Try exploring global variables that will give you an identifier value. In SQL Server, this is:

SELECT @@ identity

Also see the Scope_Identity () function

+3
source share

Must be able to SELECT @@ IDENTITY, although you will have to use a second query for this. I do not think that MS Access will allow combining it into one request.

+1
source share

All Articles