DEADPOOL
DEADPOOL

Reputation: 83

I can't delete Data in my Sqlite Database

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.

Upvotes: 0

Views: 272

Answers (1)

Giru Bhai
Giru Bhai

Reputation: 14408

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 });

Upvotes: 2

Related Questions