我需要从Sqlite中删除记录,我的表名是“TABLE_NAME”,列名是
是“COLUMN1”,我将字符串值从MyTable.java传递给mySqliteHelper.java。
我需要删除这条记录我传递的值。这是我的示例代码
给我提示或建议。任何帮助表示赞赏。
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();
}
}
答案 0 :(得分:1)
答案 1 :(得分:0)
试试这段代码:
dbHelper.delete(DATABASE_TABLE_2, KEY_NAME + "=?", new String[] { myName })