user2847219 user2847219 - 23 days ago 18
Android Question

Android SQLite db.update() add values

I'm using the method

db.update()
to change a value of a field in the table. when I insert the new value it is possible sum it with the existing?

public void Trasf() {
String value = Scegli.getText().toString();
cv.put(CTable.PREL, mI.getText().toString());

SQLiteDatabase db = mHelper.getWritableDatabase();

db.update(CTable.TABLE_NAME, cv, CTable.NO + " = ?", new String[] { value });

db.close();
}
}

Answer

Not exactly sure what you want to do but perhaps:

 public void Trasf() { 

        String value = Scegli.getText().toString();

        // add two strings or numbers together in the .put method
        cv.put(CTable.PREL, mI.getText().toString() + " " + oldString); // for string
        cv.put(CTable.PREL, int_new + int_old); // adding numbers

        SQLiteDatabase db = mHelper.getWritableDatabase();

        db.update(CTable.TABLE_NAME, cv, CTable.NO + " = ?",  new String[] { value });

        db.close(); }
    }
Comments