lundi 2 novembre 2015

Update data into SQLite table

How can i update data into Database based on id:

// Updating single record
public int update(Record record) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put("rstatus", record.getRstatus());

    // updating row
    return db.update(TABLE_RECORDS, values, "recid" + " = ?",
            new String[] { String.valueOf(record.getRecid()) });
}

MainActivity.java:

buttonUpdate.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            List<Record> record = dh.getAllR();
            for (Record dl : record) {
                long id = dl.getRecid();
                Log.d("id: ", ""+id); 
                String rname = "name: " + dl.getRname();
                Log.d("value: ", rname);  

                Record rec = new Record();
                rec.setRstatus("Done");
                dh.update(rec);

            }

        }

    });

I am trying to update rstats column of my table based on id (recid) but always getting null, where i am doing mistake ?

Aucun commentaire:

Enregistrer un commentaire