The Microsoft Access Database provides AutoNumber fieldtype which is generated automatically when a record is added in such tables which contains AutoNumber. We can fetch the auto incremented value from MS-Access database to our applications using built in function @@IDENTITY( ).
The Jet 4.0 provider supports @@Identity( ) to obtain new Identity value from Access .mdb file which returns the value of an autoincrement column that is generated on the same connection. That means the Connection object used for the Insert query must be re-used without closing it and opening it up again to fetch the Identity value as shown in the below example.
The above built-in function @@IDENTITY( ) can be used to retrieve Identity value from SQL Server too with the same above coding.
You may also like to read |