Ask Your Question
0

In MS Access with an OleDb connection, what is the process for obtaining the primary key value when executing an Insert Into command?

asked 2021-09-29 11:00:00 +0000

qstack gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-03-23 09:00:00 +0000

bukephalos gravatar image

In MS Access with an OleDb connection, the process for obtaining the primary key value when executing an Insert Into command is to use the @@Identity property. This property returns the last inserted autonumber value in the current session. To use it, you need to execute a SELECT statement immediately after the INSERT statement to retrieve the value. For example:

  1. Execute the INSERT statement:
INSERT INTO TableName (Field1, Field2, Field3)
VALUES ('Value1', 'Value2', 'Value3');
  1. Execute the SELECT statement to retrieve the autonumber value:
SELECT @@Identity;
  1. Use the value returned by @@Identity as the primary key value.
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-09-29 11:00:00 +0000

Seen: 15 times

Last updated: Mar 23 '23