Good morning. I have a problem updating data in a SQLITE database. I put the necessary code:
Variables:
public static final String TABLE_INVENTARIO_NAME = "inventario";
public static final String INV_NOMBRE="inv_nombre";
public static final String INV_TIPO="inv_tipo";
public static final String INV_NUMERO="inv_numero";
public static final String INV_IMAGEN="inv_imagen";
Creation of the database:
db.execSQL("CREATE TABLE " + TABLE_INVENTARIO_NAME + " ("
+"ID INTEGER PRIMARY KEY NOT NULL,"
+INV_NUMERO + "INTEGER NOT NULL,"
+INV_TIPO + "INTEGER NOT NULL,"
+INV_NOMBRE + "TEXT NOT NULL,"
+INV_IMAGEN + "INTEGER NOT NULL)");
Creating an initial record:
ContentValues registroInventario = new ContentValues();
registroInventario.put("ID",1);
registroInventario.put(AccesoDB.INV_NOMBRE,inv1_nombre);
registroInventario.put(AccesoDB.INV_TIPO,inv1_tipo);
registroInventario.put(AccesoDB.INV_NUMERO,inv1_numero);
registroInventario.put(AccesoDB.INV_IMAGEN,inv1_imagen);
bd.insert(AccesoDB.TABLE_INVENTARIO_NAME,null,registroInventario);
And the method to update:
private void actualizarInventario(Context context,String valorNombre, int valorImagen, int valorTipo, int valorNumero, int id){
acceso = new AccesoDB(context);
bd = acceso.getWritableDatabase();
ContentValues valores = new ContentValues();
valores.put(AccesoDB.INV_NOMBRE,valorNombre);
valores.put(AccesoDB.INV_TIPO,valorTipo);
valores.put(AccesoDB.INV_NUMERO,valorNumero);
valores.put(AccesoDB.INV_IMAGEN,valorImagen);
int up=bd.update(AccesoDB.TABLE_INVENTARIO_NAME,valores,"ID="+id,null);
if(up!=0){
Toast.makeText(context,"Se ha añadido",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(context,"Fallo",Toast.LENGTH_SHORT).show();
}
//Cerramos la BD
bd.close();
}
And the error that gives me is this:
android.database.sqlite.SQLiteException: no such column: inv_numero (code 1): , while compiling: UPDATE inventario SET inv_numero=?,inv_tipo=?,inv_nombre=?,inv_imagen=? WHERE ID=1
If I try to launch a Select it gives me a similar error:
android.database.sqlite.SQLiteException: no such column: inv_nombre (code 1): , while compiling: SELECT inv_nombre FROM inventario WHERE ID=1
I suppose there will be some problem or when creating the table or filling in the data, but I do not give with the key.
I've tried adding simple quotes to the ID but it does not work either. Any idea? Thanks and best regards.