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:

  1. add new record name:"name1", telephone: "123456789" --> new record
  2. add new record name:"name2", telephone:"987654321" --> update entered record.

if want then:

  1. be sure insert new record same id inserted one.
  2. use db.insertwithonconflict()[ link ] insert new records, passing value conflict_replace [ link ] last parameter conflictalgorithm

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

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -