Reputation: 5895
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
Reputation: 11983
Try this code:
dbHelper.delete(DATABASE_TABLE_2, KEY_NAME + "=?", new String[] { myName })
Upvotes: 0
Reputation: 9362
use something like this
db.delete(TABLE_NAME, "column_name=?", new String[]{String.valueOf(keyword)});
Refer to documentation here
Upvotes: 1