RajaReddy PolamReddy
RajaReddy PolamReddy

Reputation: 22493

How to delete specific data from a particular column in SQLite?

My app has a sqlite table which has the following columns:

The content of the column con_accid is of type String. The primary key of the table is id. I want to delete data of particular con_accid. For example, I want to delete item names of all items which have con_accid as "raja". I have tried the following different queries but both are not working:

Cursor cursor = database.query(ContactsDB.TABLE_CONTACTS, allColumns,
            ContactsDB.CONTACT_ACCID + "= ' " + comment +"'"  , null, null, null, null); 
    if (cursor != null) {
       cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            Log.i(TAG, "delete");
            ContactsInfo _comment = cursorToComment(cursor);
            long id = _comment.getId();
            database.delete(ContactsDB.TABLE_CONTACTS, ContactsDB.CONTACT_ID + "=" + id  , null);
            cursor.moveToNext();
        }
    }

and this:

String query = "SELECT * FROM todo WHERE con_accid='" + comment;
Cursor  cursor = database.rawQuery(query,null);

Upvotes: 0

Views: 2093

Answers (2)

kumar
kumar

Reputation: 691

Check "database" instance is created with .getWritableDatabase(). And your query should work without any issue.

Upvotes: 0

user
user

Reputation: 87064

This should delete all rows in your database where con_accid = raja:

database.delete(TABLE_CONTACTS, CONTACT_ACCID + " = ?", new String[] {"raja"});

Upvotes: 1

Related Questions