0

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

  • CONTACT_ID = "_id",
  • CONTACT_NAME = "con_name",
  • CONTACT_USERID = "con_userid",
  • CONTACT_ACCID = "con_accid".

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);
2
  • Your question is a little ambiguous. Do you want to delete the entire row data(all the columns) where con_accid = raja or you want to delete only the name from con_name where con_accid = raja? Commented Nov 21, 2012 at 7:38
  • i want to delete entire row where con_accid = raja those all available row in the table. Commented Nov 21, 2012 at 7:45

2 Answers 2

1

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

database.delete(TABLE_CONTACTS, CONTACT_ACCID + " = ?", new String[] {"raja"});
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.