Search code examples
c#sqlcompact-frameworksql-server-ce

Getting the primary key of a newly inserted row in SQL Server CE and C#?


I'm doing an insert into a SQL Server CE table where the primary key is auto-generated, how would I go about getting the primary key after the insertion completes?


Solution

  • Assuming your primary key is an identity field, you can use the query SELECT @@IDENTITY after you insert your new row.