-1

I am asking the C# equivalent of this question. When I insert a row of data that has an auto-increment primary key, how can I then read the primary key back?

I need this for SQlite (this answers for SQL Server).

thanks - dave

David Thielen
  • 25,233
  • 30
  • 98
  • 177

1 Answers1

2
// IDbCommand cmd
cmd.ExecuteScalar();
return ((SQLiteConnection) cmd.Connection).LastInsertRowId;

Very easy :)

David Thielen
  • 25,233
  • 30
  • 98
  • 177