I have one table TABLE_EXAM. i need to update the value of specific record by passing
id. But my code is not able to update the code. i don’t understand what is wrong in my code.
Please give me some hint or reference…
Thanks in advance..
Here is my code for reference….
public void updateExamDetails(int id,ObjectiveWiseQuestion owq)
{
SQLiteDatabase db= this.getWritableDatabase();
String selectQuery=("update exam set (examdetails, subchawise, examtype, noquestion, marks, subject_id, chapter_id) where exam_id ='"+ id +"'");
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst())
{
do {
ContentValues values = new ContentValues();
values.put(COLUMN_NO_QUESTION, owq.getNoOfQuestion());
values.put(COLUMN_MARKS, owq.getMarks());
values.put(COLUMN_CHAP_ID, owq.getChapterId());
values.put(COLUMN_SUB_ID, owq.getSubjectId());
values.put(COLUMN_SUBCHAWISE,owq.getSubChapwise());
values.put(COLUMN_EXAM_TYPE, owq.getExamType());
values.put(COLUMN_EXAM_DETAILS, owq.getExamDetails());
db.insert(TABLE_EXAM, null, values);
db.close();
}
while (cursor.moveToNext());
}
}
Logcat have one warning..
WARN/System.err(7227): android.database.sqlite.SQLiteException: near "(": syntax error: , while compiling: update exam set ( examdetails=?, subchawise=?, examtype=?, noquestion=?, marks=?, subject_id=?, chapter_id=? ) where exam_id ='1'
This is a standard way of doing it: