1

Hello everybody I would like to insert multiple records to my sqlite table at once,

This is what I've tried:

DBHelper.class

   public void insertToOUTTRANS(ArrayList<String> arrListDocumentNumber){
            ContentValues cv = new ContentValues();

            for(String text : arrListDocumentNumber){
                cv.put(KEY_DOCUMENTNUMBER, text);
            }
            myDataBase.insert(TBL_OUTTRANS, cv, null);
        }

But I'm getting error in this line:

  myDataBase.insert(TBL_OUTTRANS, cv, null);

Error says:

 The method insert(String, String, ContentValues) in the type SQLiteDatabase is not applicable for the arguments (String, ContentValues, null)

MainActivity.class:

  for(int i = 0; i< arrDocumentNumber.length; i++) {
    ArrayList<String> arrListDocumentNumber = new ArrayList<String>();
    ArrayList<String> arrListUnitOfMeasure = new ArrayList<String>();
    ArrayList<String> arrListLocationCode = new ArrayList<String>();

            arrListDocumentNumber.put(tvItemCode.getText().toString());
            arrListUnitOfMeasure.put(editText1.getText().toString));
            arrListLocationCode.put(editText1.getText().toString));

   }

But I'm kinda confused how to loop over the cursor to check for all items from the listview to save to my table. Any ideas? I would gladly appreciate your help. Thanks.

Dunkey
  • 1,900
  • 11
  • 42
  • 72

3 Answers3

3

Try this

for(int i=0;i<arrListDocumentNumber.size();i++)
{
    ContentValues initialValues=new ContentValues();
    initialValues.put(KEY_DOCUMENTNUMBER, arrListDocumentNumber.get(i));
    db.insert(TBL_OUTTRANS, null, initialValues);
}
Vaibhav Agarwal
  • 4,499
  • 3
  • 19
  • 20
1

The insert methods looks like..

insert(String, String, ContentValues)

So you need to pass arguments like..

myDataBase.insert(TBL_OUTTRANS, null, cv);  

Check syntax here.

Hardik Joshi
  • 9,477
  • 12
  • 61
  • 113
0
 myDataBase.insert(TBL_OUTTRANS, null, cv);

instead of

 myDataBase.insert(TBL_OUTTRANS, cv, null);
Gooziec
  • 2,736
  • 1
  • 13
  • 18