从表中删除行

时间:2016-05-10 20:20:27

标签: android sqlite

当我想从我的表中删除一行时,toast显示我"错误"该行已被删除

Supprimer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            db = dbhelper.getWritableDatabase();
            Cursor c = db.rawQuery("DELETE FROM Biblio WHERE nom = \""+user.getText().toString()+"\" AND type= \""+spinner.getSelectedItem().toString()+"\"",null);
            if(c.moveToFirst()){
                Toast.makeText(getActivity(), "deleted", Toast.LENGTH_LONG).show();
            }else{             Toast.makeText(getActivity(),"Erreur",Toast.LENGTH_LONG).show();}

        }
    });

1 个答案:

答案 0 :(得分:1)

rawQuery返回一个游标,但delete返回已删除的行,因此我认为rawQuery语句不常见。我会推荐以下内容:

db.delete ("Biblio", "nom = ? AND type = ?", new String[]  {user.getText().toString(), spinner.getSelectedItem().toString()})

您将获得一个int back,即已删除的行数。