-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
  • 28,723
  • 34
  • 119
  • 193

1 Answers1

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

Very easy :)

David Thielen
  • 28,723
  • 34
  • 119
  • 193