lantonis
lantonis

Reputation: 143

Delete values from sqlite android

On my app I read some values that I added to the database and I insert them into a spinner. I want to delete any value I want but the error message ways there is no column with that name. Even though my spinner fills up with values. Error message:

android.database.sqlite.SQLiteException: no such column: bmw (code 1), while compiling: DELETE FROM MyCars WHERE MyCarsBrand=bmw at android.database.sqlite.SQLiteConnection.nativePrepareStatement

Here is my code:

            if (db.deleteTitle(deleteSpinner.getSelectedItem().toString()))
                Toast.makeText(DeleteCarActivity.this,
                        "Delete successful.", Toast.LENGTH_LONG).show();
            else
                Toast.makeText(DeleteCarActivity.this, "Delete failed.",
                        Toast.LENGTH_LONG).show();
            db.close();

Other class

    public boolean deleteTitle(String rowId) 
    {
        return db.delete(MY_CARS_TABLE, MY_CARS_BRAND_COLUMN + 
                "=" + rowId, null) > 1;
    }

Upvotes: 0

Views: 192

Answers (1)

MysticMagicϡ
MysticMagicϡ

Reputation: 28823

Replace

return db.delete(MY_CARS_TABLE, MY_CARS_BRAND_COLUMN + 
                "=" + rowId, null) > 1;

with

return db.delete(MY_CARS_TABLE, MY_CARS_BRAND_COLUMN + 
                "='" + rowId + "'", null) > 1;

You need '' around string arguments.

Upvotes: 1

Related Questions