1

I want to insert multiple values in the database when in click the save button but the code not work correctly ?

public void insert(String note) {
        ContentValues cv = new ContentValues();
        ContentValues cv1 = new ContentValues();
        ContentValues cv2 = new ContentValues();
        cv.put("note", note);
        cv1.put("topic",topic1);
        cv2.put("subTopic",subTopic1);
        getWritableDatabase().insert("Notes", "note", cv);
        getWritableDatabase().insert("Notes", "topic", cv1);
        getWritableDatabase().insert("Notes", "subTopic", cv2); }




private View.OnClickListener onSave = new View.OnClickListener() {

    public void onClick(View v) {
        if (noteId == null) {
            helper.insert(editNote.getText().toString(), , );
        } else {
            helper.update(noteId, editNote.getText().toString());
            noteId = null;
        }
        ourCursor.requery();
        editNote.setText("");
    }
};

1 Answer 1

2

Try this code for inserting mutiple columns :

public void insert(String note,String topic,String subTopic) {
     ContentValues initialValues = new ContentValues();
     initialValues.put("note", category);
     initialValues.put("topic", notes_date);
     initialValues.put("subTopic", notes_date);
     mDb.insert(DATABASE_TABLE, null, initialValues);
}

Where mdb is instance SQLiteDatabase mDb= mDbHelper.getWritableDatabase();

DATABASE_TABLE - table name.

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.