Creating a SQLite table row updating row again and again -
i have created table application... first time user give input 2 edittext ,name , mobile number when table empty after updating first row of table...so on
a scenario:
- add new record name:"name1", telephone: "123456789" --> new record
- add new record name:"name2", telephone:"987654321" --> update entered record.
if want then:
- be sure insert new record same
id
inserted one. - use
db.insertwithonconflict()
[ link ] insert new records, passing valueconflict_replace
[ link ] last parameterconflictalgorithm
sample code
void add_contact(person_contact contact) { db = this.getwritabledatabase(); contentvalues values = new contentvalues(); // single_row_id constant holding single row id used. e.g: single_row_id = 1 values.put( key_id, single_row_id ); values.put( key_name, contact.get_name() ); // contact name values.put( key_ph_no, contact.get_phone_number()); // contact phone // inserting row db.insert( table_contacts, null, values ); db.insertwithonconflict( table_contacts,key_id,values, sqlitedatabase.conflict_replace ); db.close(); // closing database connection }
Comments
Post a Comment