Reputation: 147
I have created a table for my application... first time user will give the input for two editText ,name and mobile number when table is empty after that only updating the first row of table...so on
Upvotes: 0
Views: 140
Reputation: 2730
A scenario:
If that what you want then:
id
as the previously inserted one.db.insertWithOnConflict()
[ link ] to insert new records, passing the value CONFLICT_REPLACE
[ link ] for the last parameter conflictAlgorithm
Sample Code
void Add_Contact(Person_Contact contact)
{
db = this.getWritableDatabase();
ContentValues values = new ContentValues();
// SINGLE_ROW_ID is a constant holding the single row id that will be 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
}
Upvotes: 1