Update on sqlite does not update data

Asked

Viewed 149 times

1

Hello, someone could 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();
       } // 
  • @Thiagorideraugusto his editions are not improving the understanding of the question (which by the way is not very clear by itself). For this reason I rejected your editions.

  • Matheus, your question is a little confused, edit it explaining better the problem faced.

  • Could add the method updateReceita ?? That’s where it’s not working, correct?

  • ok edited the Question

  • problem solved...thanks

1 answer

0

Try to update as follows:

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

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

The values shall be linked as String.

Follows the documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.