Linked Questions

Popular Questions

How to Populate values from Array into SQLite Database

Asked by At

my App receives user input data via one EditText field and adds to an Array. The App then passes the Array via databasehelper controller to the Helper class using the code

controller.populateStockMaterialDB(InventoryData); 

In my Database helper I have the following code to read the array and populate the database table with 6 values from the Array

public void populateStockMaterialDB(ArrayList<String> inventoryData) {
        SQLiteDatabase db = this.getWritableDatabase();

        for (int i=0; i< inventoryData.size(); i++) {
         ContentValues contentValues = new ContentValues();
            contentValues.put(FoodoclockContract.FoodolockEntry.COLUMN_MATERIAL, inventoryData.get(i));
            contentValues.put(FoodoclockContract.FoodolockEntry.COLUMN_UOM_STORE, inventoryData.get(i));
            contentValues.put(FoodoclockContract.FoodolockEntry.COLUMN_UOM_AVAILABLE, inventoryData.get(i));
            contentValues.put(FoodoclockContract.FoodolockEntry.COLUMN_QUANTITY_STORE, inventoryData.get(i));
            contentValues.put(FoodoclockContract.FoodolockEntry.COLUMN_QUANTITY_AVAILABLLE, inventoryData.get(i));
            contentValues.put(FoodoclockContract.FoodolockEntry.COLUMN_MOQ, inventoryData.get(i));

            this.getWritableDatabase().insertOrThrow(FoodoclockContract.FoodolockEntry.TABLE_NAME7, "", contentValues);
        }
    }

The Array data is populated into the table but not correctly. Instead of having one row with 6 columns populated with data, I have 6 rows with 6 columns populated with data. I would appreciate some help with my code. thank you

Related Questions