SQLite: new ID at Insert Add
How do you get the new ID when inserting a record in SQLite?
Solution:
The return value of a Sqlite.Insert statement always automatically returns the new ID of a table if there is an integer autoimcrement column.
In case of an error, a -1 is output as
long newID = db.insert("tbl_Notes", null, values); |
In a dive structure, which has a unique ID field.
To do this, when creating the SQLite table, specify Integer Primary Key Autoincrement
CREATE TABLE tbl_Notes ( IDNote INTEGER PRIMARY KEY AUTOINCREMENT .. |
public long add_Note(String
sTitle, String sText, Date dtNoteDay) {
|
Database on Android
In localhost-> sqlite
Database in SQLite on Android: http://192.168.178.23:8080/# (Android Debug Database)
IDNote |
Title |
Text |
dtDay |
dtEdit |
5 |
dfffcName |
2018-09-28 17:33:52 |
||
11 |
not online |
2018-09-28 18:03:20 |
||
12 |
new Data |
2018-09-28 18:05:12 |
||
13 |
924Name |
2018-10-01 07:23:11 |
Matching table structure:
@Override
|