0

In my app, I declared my '_id' as string (because my ID includes dashes ('-') ).

Here's my code:

    /**
     * Database creation SQL statement
     */
    private static final String DATABASE_CREATE =
            "create table " + DATABASE_TABLE + " ("
                    + KEY_ImagePathID + " text not null, "
                    + KEY_ImagePath + " text not null);";

Now In my adapter class I have the following code to delete data:

public void delete_Pic_byID(String id){
        mDb.delete(DATABASE_TABLE, KEY_ImagePathID+"="+id, null);

    }

The problem now is I cant delete a data when it contains other character aside from numeric characters. But when the ID is numeric, it works perfectly. I'm new to android development and I hope you can help me.

1 Answer 1

2

You missed single quote,So change

  mDb.delete(DATABASE_TABLE, KEY_ImagePathID+"="+id, null);

to

  mDb.delete(DATABASE_TABLE, KEY_ImagePathID+"='"+id + "'", null);

Recommanded solution is to use parameterized query as

mDb.delete(DATABASE_TABLE, KEY_ImagePathID + " = ?",new String[] { id });
3
  • Thank you very much for your quick response! I've been trying to figure this out for hours! You're a life Saver. :)
    – DEADPOOL
    Sep 18, 2014 at 13:33
  • I'll accept this as the answer after 10 minutes. :)
    – DEADPOOL
    Sep 18, 2014 at 13:33
  • @DEADPOOL happy to help,try to use recommended solution.
    – Giru Bhai
    Sep 18, 2014 at 13:34

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.