我正在尝试从SQLite删除一行,但是我不能,Eclipse不会说我没有错误。我可以插入并删除所有内容,但是当我要删除一行时,什么也不做
public void AlertDialogLimpiarProducto(final int position){
AlertDialog.Builder aviso = new AlertDialog.Builder(Carrito.this);
aviso.setTitle("Alerta");
aviso.setMessage("¿Desea borrar el producto?");
aviso.setPositiveButton("Confirmar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogo1, int id) {
try{
db = usdbh.getWritableDatabase();
db.execSQL("DELETE FROM Carrito WHERE nombre = '" + nombre_producto +"'");
cuentas.remove(position);
//PARA BAJAR EL CONTADOR DEL ACTIVITY PRINCIPAL
MainActivity.contador_carrito--;
MainActivity.cantidad_carrito.setText(MainActivity.contador_carrito+"");
Toast.makeText(Carrito.this, nombre_producto+" eliminado", Toast.LENGTH_SHORT).show();
db = usdbh.getReadableDatabase();
db.close();
}catch(Exception e){
e.printStackTrace();
}
}
});
aviso.setNegativeButton("Cancelar", null);
aviso.show();
}
理想情况下,如果它不适用于您的设备,则应与execSQL一起
使用,请尝试使用delete方法
db.delete(table_name, where, whereArgs);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句