0

I have a table with columns : transaction_name | member1 | member2 | member3 | member4

In my activity, I will receive a String array of column names of this table, say columnarray[] = {"member1","member3","member4"}

and also I will receive a Integer array of column values to insert into those particular columns, say valuearray[] = {value1,value3,value4}

Now, in my activity, I have to write a query such that i have to insert these values(in integer array) into these columns(in string array) dynamically.

Simply, the following action should be performed :

"INSERT into tablename(member1,member3,member4) values(value1,value3,value4)"

As I will receive these column names and column values from arrays, how can i perform this insertion operation on my table dynamically?

1 Answer 1

1

Using an ordinary SQLiteDatabase:

ContentValues values = new ContentValues();
for (int i = 0; i < columnarray.length(); i++) {
    values.put(columnarray[i], valuearray[i]);
}
database.insert("tablename", null, values);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.