Reputation: 5895
I have two table "TABLE_EXAM" and "TABLE_QUESTION". I need to store the question in table with exam id. My question is that how to gel last id of exam table?
Thanks in advance..
Edited Question
Here is my sample code.
public int getLastExamId()
{
int id2=0;
try
{
SQLiteDatabase db=this.getWritableDatabase();
Cursor cursor=db.rawQuery("SELECT * from SQLITE_SEQUENCE", null);
if(cursor.moveToLast())
{
id2=cursor.getInt(0);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return id2;
}
Upvotes: 1
Views: 1993
Reputation: 4445
if you are inserting data using
db.insert(TABEL_NAME, null, values);
then the return value from this function is the id of the row.
Upvotes: 4