我想添加或更新Android中的SQLite數據庫中的信息。 數據庫獲取課程筆記ID和學生ID。如果課文標識爲0,則會創建一個新條目。Android SQLite更新/插入數據不會工作
這裏是什麼在我的Dbhelper類(插入,更新是相當類似):
public boolean insertLessonNotes(LessonNotesData lData)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues lessonValues = new ContentValues();
//values.put(LESSON_ID, lData.getLessonID()); // Lesson ID
//values.put(ST_ID, lData.getStudentID()); // Student ID
//values.put(LESSON_IMAGE_ID, lData.getImageID()); // Lesson Image ID
//values.put(LESSON_IMAGE_NOTE, lData.getImageNote()); // Note attached to image
lessonValues.put(LESSON_ID, lData.getLessonID());
lessonValues.put(ST_ID, lData.getStudentID());
lessonValues.put(DATE, lData.getDate()); // Date note added
lessonValues.put(LESSON_READING, lData.getReadingNote()); // reading notes
lessonValues.put(LESSON_PHONICS, lData.getPhonicsNote()); // phoncis notes
lessonValues.put(LESSON_SPELLING, lData.getSpellingNote()); // spelling notes
lessonValues.put(LESSON_WRITING, lData.getWritingNote()); // writing notes
lessonValues.put(LESSON_COMMENTS, lData.getCommetns()); // comments notes
lessonValues.put(LESSON_HOMEWORK, lData.getHomework()); // homework notes
// Inserting Row
db.insert(TABLE_LESSON_NOTES, null, lessonValues);
db.close();
return true;
}
這是我lessonNotes類(其中輸入和保存的信息)
LessonNotesData lNote = new LessonNotesData(id_To_Update, student_id, lessonDate.getText().toString(), readNote.getText().toString(), phonNote.getText().toString(), spellNote.getText().toString(), writeNote.getText().toString(), commentNote.getText().toString(), homeworkNote.getText().toString());
Bundle extras = getIntent().getExtras();
int studentID = extras.getInt("studentId");
int lessonID = extras.getInt("lessonID");
Toast.makeText(getApplicationContext(), "LessonID is:(lessonNotes3) "+String.valueOf(lessonID), Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "StudentID is: (lessonNotes3) "+String.valueOf(studentID), Toast.LENGTH_SHORT).show();
//Bundle studentId = getIntent().getExtras();
if (lessonID != 0) {
if (studentID > 0) {
if (mydb.updateLessonNotes(lNote)) {
//Update was successful
Toast.makeText(getApplicationContext(), "Updated successfully", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(), com.example.ltss.dyslexia.app.LessonNotesList.class);
intent.putExtra("studentId",studentID);
startActivity(intent);
} else {
//Update did not complete correctly
Toast.makeText(getApplicationContext(), "Update unsuccessful, Please try again", Toast.LENGTH_SHORT).show();
}
} else {
if (mydb.insertLessonNotes(lNote)) {
Toast.makeText(getApplicationContext(), "New Lesson note created", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Error creating lesson note! Please try again", Toast.LENGTH_SHORT).show();
}
//Return user to lessonNotesList where ListView should now show new lesson note
Intent intent = new Intent(getApplicationContext(), com.example.ltss.dyslexia.app.LessonNotesList.class);
intent.putExtra("studentId",studentID);
startActivity(intent);
}
}
每當我嘗試添加或更新系統中的任何東西,我得到這個從調試日誌:
04-02 20:02:33.925 26789-26789/com.example.ltssdyslexiaapp D/Items to add:﹕ [email protected]
關於這是什麼或我如何解決它的任何想法?
感謝
如果**總是返回true **,那麼**布爾**函數的用途是什麼?你可以發佈你的'表格創建'代碼嗎? – 2015-04-03 07:55:48