给出以下代码:
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);");
在SQLite中创建一个表。
如何在添加记录后获取lastID?
使用以下代码:
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);
我得到-1
。
答案 0 :(得分:6)
public long insert (String table, String nullColumnHack, ContentValues values)
返回
新插入行的rowID
,如果发生错误,则为-1
。