I'm writing an INSERT using SQLite, and either I am using an AUTOINCREMENT or just going to use the ROWID as the primary key. Once the INSERT is performed, how do I find out what the primary key is for the row I just inserted?
I know what to do if I were working in Sql Server, but this is SQLite.
Here's my code:
public bool AddPlanet(Planet p)
{
bool result = false;
SQLiteConnection sqlConnection;
using (sqlConnection = new SQLiteConnection(ConnString))
{
sqlConnection.Open();
sqlCommand = new SQLiteCommand(sqlConnection);
sqlCommand.CommandText =
String.Format(
"insert into planet (name, satellites) values ('{0}',{1})"
, p.Name
, p.Satellites.ToString()
);
sqlCommand.CommandType = CommandType.Text;
int x = sqlCommand.ExecuteNonQuery();
// WHAT DO I DO HERE TO FIND OUT THE ROWID OF
// THE ROW THAT WAS JUST INSERTED?
if (x > 0) result = true;
sqlConnection.Close();
}
return result;
}