Adding data to sqlite database give 2 arrays containing the data
This is a hard one to explain but here goes. I have 2 arrays, one with the column names of the table I want to insert into ([column1, column2, column3 etc...])
and the second array contains the data to be inserted in the same array positions as the first array, ([data1, data2, data3 etc...])
I would like to know how to create an sql query from these values in the arrays so I can execute the statement. I have a feeling the best way is to either use ContentValues (I have no idea where to start with that) or the db.insert()
command. it would be very easy if there was a way to pair up each item from the first array with the data item for the second and then somehow add them to the database. Oh and the data stored in the secon开发者_开发百科d array is made up of more than one datatype which I guess makes this more difficult.
Sorry if this is a confusing and long winded question.
ContentValues initialValues = new ContentValues();
for(int i=0;i
{ initialValues.put(array[i], array2[i]);}
long rawId = db.insert(TABLE_NAME, null, initialValues); Log.i("RawID", "Raw ID:"+rawId);
as i write above you can do with for loop and using arrays
精彩评论