Reputation: 504
I am working on Winforms applications and binding the SQL data source through designer. i need to get the proper primary key value of the newly added record. if the last PK value was 10 and added or removed some rows, then dataset generated PK value would be 11 while the real PK value in SQL server would be 14. Please suggest me any ideas.
Thanks in Advance.
Upvotes: 1
Views: 188
Reputation: 1384
If you can write the SQL clause yourself, you can use the OUTPUT clause. Works both for insert and update.
e.g.
INSERT AValueColumnName
OUTPUT PrimaryKeyColumnName
INTO mytable
VALUES (1)
Upvotes: 2