dimanche 22 novembre 2015

Deleting a row from a SQLite database by passing a username?

I was working on deleting a specific row from my SQLite database by passing in the username as an argument.
Now, this is what happens.

If I pass the row id, everything works fine but when I pass in KEY_Name = username, nothing happens.

So, I am really confused now.
Can anyone suggest me why is this error showing up?
The same problem happens with my update Button.

public void deleteUser(String userName)
        {
            try
            {
                SQLiteDatabase db = helper.getWritableDatabase();
                db.delete(DATABASE_TABLE, KEY_NAME + "=" + userName,null);
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }

        }

case R.id.button4:

              String sr = t7.getText().toString();

              Electronicscheckout exht = new Electronicscheckout(this);
              try {
                  exht.open();
                  exht.delete(sr);
                  exht.close();
              } catch (SQLException e) {
                  Dialog d = new Dialog(this);
                  d.setTitle("Dang");
                  TextView tv = new TextView(this);
                  tv.setText("error");
                  d.setContentView(tv);
                  d.show();
              }
              break;

The thing that really surprises me is that the following code work if I pass in row id as an argument as following:-

public void deleteUser(Long id)
        {
            try
            {
                SQLiteDatabase db = helper.getWritableDatabase();
                db.delete(DATABASE_TABLE, KEY_ROWID + "=" + id,null);
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }

        }

Aucun commentaire:

Enregistrer un commentaire