Sandip Armal Patil
Sandip Armal Patil

Reputation: 5895

How to delete record using SQLiteDatabase?

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();
    }

}

Upvotes: 0

Views: 2429

Answers (2)

Durgpal Singh
Durgpal Singh

Reputation: 11983

Try this code:

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

Upvotes: 0

Rahul garg
Rahul garg

Reputation: 9362

use something like this

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

Refer to documentation here

Upvotes: 1

Related Questions