2

Given the following code:

 sqLiteDatabase.execSQL("create table if not exists ACCOUNT (ID integer primary key autoincrement," + "CASH LONG NOT NULL," + "BANKID INTEGER NOT NULL," + "ACCOUNTNO TEXT ," + "DATE TEXT NOT NULL," + "COMMENT TEXT);"); 

A table is created in SQLite.

How can I get a lastID after adding a record?

With the following code:

 contentValues.put("CASH", accountTO.getCash()); contentValues.put("DATA", DatePro.currentDate()); contentValues.put("BANKID", accountTO.getBankID()); contentValues.put("ACCOUNTNO", accountTO.getAccountNo()); contentValues.put("COMMENT", accountTO.getComment()); Long i = sqLiteDatabase.insert("ACCOUNT", null, contentValues); 

I get -1.

4
  • 1
    get the ID which is max Commented Jun 14, 2013 at 6:55
  • possible duplicate of Get last inserted value from sqlite database Android Commented Jun 14, 2013 at 6:57
  • Record ID which has already been added Commented Jun 14, 2013 at 7:04
  • Column name DATE in create table, DATA in contentValues. Fix that first. Commented Jun 14, 2013 at 8:22

1 Answer 1

6
public long insert (String table, String nullColumnHack, ContentValues values) 

Returns the rowID of the newly inserted row, or -1 if an error occurred.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.