mardi 5 mai 2015

No such column exists error when inserting into sqlite database

I am having trouble inserting records to my application local database. I am getting data from web services and tried to store them inside my app local sqlite database but i am getting no such table error. This is the code of my DatabaseHelper class that i am using for table creation & inserting into it.

private static final String CREATE_MERCHANT_DETAILS = "CREATE TABLE " + TABLE_MERCHANT_DETAILS + 
    " (" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + 
    KEY_NAME + " TEXT, " 
    + KEY_LOGO + "TEXT, " 
    + KEY_BACKGROUND + "TEXT, " 
    + KEY_PRODUCT + "TEXT, " 
    + KEY_PRODUCT_ID + "TEXT, " 
    + KEY_TYPE + "TEXT, " 
    + KEY_DENOMINATION + "TEXT);";


public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        this.context = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_MERCHANT_DETAILS);
    }

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

    public void insertAMerchant(String name, String logo, String background, String product, String productId, String type, String denomination) {
        database = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(KEY_NAME, name);
        contentValues.put(KEY_LOGO, logo);
        contentValues.put(KEY_BACKGROUND, background);
        contentValues.put(KEY_PRODUCT, product);
        contentValues.put(KEY_PRODUCT_ID, productId);
        contentValues.put(KEY_TYPE, type);
        contentValues.put(KEY_DENOMINATION, denomination);
        database.insert(TABLE_MERCHANT_DETAILS, null, contentValues);
    }

Aucun commentaire:

Enregistrer un commentaire