tags:

views:

41

answers:

1

A piece of code to update DB raw:

private EditText et;
//...
private void updateRecipe(){
  SQLiteDatabase db=recipes.getWritableDatabase();
  ContentValues values=new ContentValues();
    values.put(RECIPE, et.getText().toString());
  db.update(RECIPES_TABLE, values, "id=?", new String[]{id});

} When running error occures:

Error updating recipe=Efrerer using UPDATE recipes SET recipe=? WHERE id=? android.database.sqlite.SQLiteException: no such column: id: , while compiling: UPDATE recipes SET recipe=? WHERE id=?

As requested:

  @Override

public void onCreate(SQLiteDatabase db){ db.execSQL("CREATE TABLE "+CATEGORY_TABLE+" ("+_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+ CATEGORY_NAME+" TEXT NOT NULL);");

  db.execSQL("CREATE TABLE "+RECIPES_TABLE+" ("+_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+
          RECIPE_NAME+" TEXT NOT NULL, "+CATEGORY_ID+" INTEGER, "+ RECIPE+" TEXT NOT NULL);");

} public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){

  db.execSQL("DROP TABLE IF EXISTS "+CATEGORY_TABLE);
  db.execSQL("DROP TABLE IF EXISTS " +RECIPES_TABLE);

}

+1  A: 

Please, post statements you use to create db. It seems that you just don't create the appropriate column.

All you need is to check what value your _ID variable contains. May be it differs somehow from the desired 'id' you used in your update statement?

Vladimir Ivanov
db.update(RECIPES_TABLE, values, "_id=?", new String[]{id});
Alex Volovoy
Thanks, that was total inattention.
Mighter