0

在我的应用程序中,我读取了一些添加到数据库中的值,并将它们插入到微调器中。我想删除我想要的任何值,但错误消息表示没有具有该名称的列。即使我的微调器充满了值。错误信息:

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

这是我的代码:

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

其他类

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

1 回答 1

1

代替

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

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

您需要 '' 围绕字符串参数。

于 2013-01-22T06:34:04.433 回答