给定以下代码:

 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

最佳答案

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

退换商品
新插入行的rowID,如果发生错误则为-1

10-08 18:11