0

I need to delete the record from Sqlite, My table name is "TABLE_NAME" and column name
is "COLUMN1", I pass the string value from MyTable.java to mySqliteHelper.java.
I need to delete this record which value I pass. Here is my sample code.
Give me hint or suggestion. Any help is appreciated.

MyTable.java

AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle("Delete Profile");
    alert.setMessage("You want to delete this profile?");       
    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener()
    {
        public void onClick(DialogInterface dialog, int whichButton)
        {         
            MySQLiteHelper m=new MySQLiteHelper(getBaseContext());
            m.deleteBName(other);   
            deleteMessage();
        }
    });     

MySQLitHelper.java

public void deleteBName(String keyword) 
{
    try
    {
        SQLiteDatabase db=this.getWritableDatabase();
        db.delete(TABLE_NAME, COLUMN1+"="+keyword, null);   
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

}

2 Answers 2

1

use something like this

db.delete(TABLE_NAME, "column_name=?", new String[]{String.valueOf(keyword)});

Refer to documentation here

Sign up to request clarification or add additional context in comments.

2 Comments

db.delete() return the rows affected..so for debugging , do int temp = db.delete(...); and check if the rows are getting affected or not,, otherwise it might be minor problem with spelling or something.... btw the second parameter must be as it is, like COLUMN1+"=?" no reference to keyword here...
Hey thanks! it's working.actually i enter wrong column name....Thank you very much...
0

Try this code:

dbHelper.delete(DATABASE_TABLE_2, KEY_NAME + "=?", new String[] { myName })

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.