I created a database for students with fields Name, surname, marks and I did insert and view sucessfully
but I don't know how to do Update and Delete.
Please help here I want to do update and delete based on ID.
Asked
Active
Viewed 3,537 times
3

Karthick
- 584
- 4
- 25
1 Answers
3
In DatabaseHandler class,
for update
:
public long update(String id,String name,String surname,String marks) {
ContentValues contentValues= new ContentValues();
contentValues.put(COL_2,name);
contentValues.put(COL_3,surname);
contentValues.put(COL_4,marks);
return mDb.update(TABLENAME, contentValues,"ID=?",new String[] {id});
}
For Delete Use:
public long delete(String ID){
ContentValues args = new ContentValues();
return mDb.delete(TABLENAME,"ID=?",new String[]{ID});
}

galath
- 5,717
- 10
- 29
- 41

GIRIDHARAN
- 169
- 1
- 1
- 14
-
Its simple use to update `myDB.update(id,name,surname,marks);` for delete `myDB.delete(ID);` – GIRIDHARAN Sep 24 '15 at 18:05
-
we can't use this line in mainactivity??myDB.update(updatename.getText().toString(),updatesurname.getText().toString(),updatemark.getText().toString()); – Karthick Sep 24 '15 at 18:07
-
Yes you can these and all basic things [refer](http://www.vogella.com/tutorials/AndroidSQLite/article.html) – GIRIDHARAN Sep 24 '15 at 18:10
-
it shows me error on this line updatename.getText().toString(),updatesurname.getText().toString(),updatemark.getText().toString() – Karthick Sep 24 '15 at 18:12
-
then check the datatype and number of arguments your passing to updates are same. – GIRIDHARAN Sep 24 '15 at 18:17