Update in sqlite does not update data

1

Hello, could anyone help me, the update is not updating the data!

Follow the button that calls the method:

@Override
    public void onClick(View v) {


        Receita rec = new Receita();
        String dosradio = null;
        switch(rg.getCheckedRadioButtonId()){
        case R.id.rbCmp:
            dosradio = "cmp";
            break;
        case R.id.rbMl:
            dosradio = "ml";
            break;

        }
         if (getIntent().getExtras() == null){

        rec.setMedicamento(txtMedi.getText().toString());
        rec.setDosagem(txtDos.getText().toString());
        rec.setHorario(spn1.getSelectedItem().toString());
        rec.setVencimento(txtDt.getText().toString());
        rec.setdosradio(dosradio.toString());
        bdhelper.insertRec(rec);
         }
         else{

             rec.setMedicamento(txtMedi.getText().toString());
                rec.setDosagem(txtDos.getText().toString());
                rec.setHorario(spn1.getSelectedItem().toString());
                rec.setVencimento(txtDt.getText().toString());
                rec.setdosradio(dosradio.toString());
                bdhelper.updateReceita(rec);

         }

     }

        public void updateReceita(Receita rec) 
       {
          db = getWritableDatabase();
          ContentValues editContact = new ContentValues();
          editContact.put("medicamento", rec.getMedicamento());
          editContact.put("dosagem", rec.getDosagem());
          editContact.put("dosradio", rec.getdosRadio());
          editContact.put("horario", rec.getHorario());
          editContact.put("venciment", rec.getVencimento());

          db.update("tab", editContact, "_id=" + rec.getId(), null);
          db.close();
       } // 
    
asked by anonymous 29.09.2016 / 03:30

1 answer

0

Try to perform the update as follows:

db.update("tab", editContact, "_id = ?", new String[]{rec.getId().toString()});
db.close();

You can include ? in the WHERE clause, which will be replaced by the fourth parameter values.

The values will be linked as String .

Follow the documentation.

    
29.09.2016 / 18:04