我有一个表TABLE_EXAM。我需要通过传递
id来更新特定记录的值。但我的代码无法更新代码。我不明白我的代码中有什么问题。
请给我一些提示或参考... 在此先感谢..
这里是我的参考代码....如何更新Sqlite的内容?
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中有一个警告..
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'
我只是猜测这里,但是我希望你的查询字符串需要一些参数绑定(通常像'set examdetails =?,subchawise =?,...')。 – bdares 2012-03-31 09:01:35
没有..它不工作 – 2012-03-31 09:04:07