Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a row from a table in SQLite android? [duplicate]

Tags:

android

sqlite

I have done this and it is not working. I am getting force close.

public boolean favoriteDelete(int id) {
    return database.delete("FavoriteData", "Google" + "=" + id, null) > 0;
}
like image 421
sai Avatar asked Jan 03 '12 05:01

sai


People also ask

How can I delete duplicate rows in a table?

If a table has duplicate rows, we can delete it by using the DELETE statement. In the case, we have a column, which is not the part of group used to evaluate the duplicate records in the table.

How do I delete duplicates in SQLite?

The DISTINCT clause allows you to remove the duplicate rows in the result set. In this syntax: First, the DISTINCT clause must appear immediately after the SELECT keyword. Second, you place a column or a list of columns after the DISTINCT keyword.

How can I delete duplicate rows in the same table in SQL?

To delete the duplicate rows from the table in SQL Server, you follow these steps: Find duplicate rows using GROUP BY clause or ROW_NUMBER() function. Use DELETE statement to remove the duplicate rows.


2 Answers

You can simply use sql query to delete.

public void delete(String id) {
        db.execSQL("delete from "+TBL_NAME+" where Google='"+id+"'");
    }

In your query you are passing null in place of whereArgs

db.delete(table, whereClause, whereArgs)

It should be like this

db.delete(TBL_NAME, "Google=?", new String[]{Integer.toString(id)});
like image 87
Lalit Poptani Avatar answered Oct 04 '22 18:10

Lalit Poptani


Try this

public boolean favoriteDelete(int id) {
    return db.delete(DATABASE_TABLE, KEY_ROWID +  "=" + id, null) > 0;
}
like image 26
diya Avatar answered Oct 04 '22 17:10

diya