mercredi 28 octobre 2015

can not updates data on SQLite

I have a simple android apps and containt function to update SQLite. I have tried a simple function from Android Tutorial in WM Lee eBook but this method didn't effect my DB. Here is my Update code

public boolean updateData(Pelanggan pl)
{
    ContentValues init = new ContentValues();
    init.put(VAR_NAMA, pl.getNama());
    init.put(VAR_ALAMAT, pl.getAlamat());
    init.put(VAR_BIRTH, pl.getTgl_lahir());
    init.put(VAR_IK, pl.getIbu_kandung());

    return db.update(DATABASE_TABLE, init, VAR_IK + "=?", new String[] { (VAR_KTP) }) > 0;
}

This is my implementation of that function

Pelanggan pelanggan = new Pelanggan();
pelanggan.setNama(et_name.getText().toString());
pelanggan.setKtp(et_ktp.getText().toString());
pelanggan.setAlamat(et_address.getText().toString());
pelanggan.setIbu_kandung(et_ibuKandung.getText().toString());
pelanggan.setTgl_lahir(birth);
if(dbPelanggan.updateData(pelanggan))
{
     Toast.makeText(getBaseContext(), "Success", Toast.LENGTH_LONG).show();
}
else
{
     Toast.makeText(getBaseContext(), "Failed", Toast.LENGTH_LONG).show();
}

The problem is it's always show "Failed" and also DB didn't update. I will be happy if someone can help me. Thank you before

Aucun commentaire:

Enregistrer un commentaire