2

给定以下代码:

 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

4

1 回答 1

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

返回rowID新插入行的 ,或者-1如果发生错误。

于 2013-06-14T07:00:10.627 回答