Retrieving ID of added record?

  • Thread starter Thread starter jay
  • Start date Start date
J

jay

To get Autonumber ID of record just added in Access database, in old ADO I
used "SELECT @@Identitiy", executed it and read the first field in the
returned recordset.

I have tried using that same way in ADO.NET but unsuccessfully. Executing
the above query always returns zero (0).

Anyone knows any other way?

thanks,
jay
 
You can use SELECT SCOPE_IDENTITY(), execute this statement in the same
batch as the insert statement. Might be better to place it with your insert
statement in a stored procedure.

I'm not sure if this works for Access but it will work for SQL Server and
MSDE. If I were you I'd switch to MSDE instead of Access
 
Back
Top