samedi 26 mars 2016

Get an error when want to insert 2 arguments and when it is only one it's okay

Hey guys can someone tell me why my method addAlarm works when I add only single "alarm" and when I want to add some name for my alarm I get an error that says no such column: alarmname (code 1): , while compiling: INSERT or replace INTO alarms (alarm,alarmname) VALUES(1459006407264,alarmname) here I wanted to add an alarm that have a name "alarmname". How can fix this? This is how I create table:

public void onCreate(SQLiteDatabase db) {
        String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_ALARMS + "("
                + KEY_ID + " INTEGER PRIMARY KEY , " + KEY_ALARM + " TEXT, "
                +  KEY_NAME + " TEXT" + ")";
        db.execSQL("create table alarms ("
                + "id integer primary key,"
                + "alarm text,"
                + "name text," // added a ','
                + "alarmname text" + ");");
    }

And my addAlarm method:

void addAlarm(Alarm alarm) {
        SQLiteDatabase db = this.getWritableDatabase();

        String sql =
                "INSERT or replace INTO alarms (alarm,alarmname) VALUES("+ alarm.getAlarm() + ","+ alarm.getName() + ")" ;
        db.execSQL(sql);
        db.close(); // Closing database connection
    }

Aucun commentaire:

Enregistrer un commentaire