Search code examples
javaandroidsqliteandroid-sqlite

Can not update the data of SQLite database in Android


I try to update my data in the SQLite database but when I do db.update the ide through an error and convince me to create a local var for it

public void updateEmployee(int sno, String name, double increment){
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues v= new ContentValues();

        v.put("mytag sno", sno);
        v.put("mytag name", name);
        v.put("mytag increment", increment);

        db.update("myemployee","sno=?", new String[]{String.valueOf("sno"),new String[]{});
        db.close();

    }

Solution

  • Try using

    db.update("myemployee",v, "sno=?",new String[]{String.valueOf("sno"));
    

    As update statement works like this

    database.update("Table name","Contentvalues",where clause, value of where clause);