1
我正在使用以下方法更新帶編輯數據的SQLite表。我編輯屏幕的方式是,通過單擊表格視圖的每一行(從XML獲取數據),它會導航到一個頁面,在該頁面中有一個文本字段可輸入編輯的數據。以編程方式編輯SQLite數據庫中的數據
我在該類中有一個「保存」按鈕。我沒有得到如何在保存按鈕事件處理程序中調用此方法。任何人都可以給我一些很好的教程鏈接或示例代碼以編程方式編輯SQLite數據?
- (void) saveUpdatedStudentData {
if(updateStmt == nil) {
const char *sql = "update tbl_Students Set StudentName = ?,Age =?,Gender =?,DOB =?,StudentID =?,BloodGroup =?,Address =?,Class =?,Section =?,Stream =?,LastName =?,MiddleName =? Where tbl_ID = ?";
if(sqlite3_prepare_v2(database, sql, -1, &updateStmt, NULL) != SQLITE_OK) {
NSAssert1(0, @"Error while creating update statement. '%s'", sqlite3_errmsg(database));
}
sqlite3_bind_text(updateStmt, 1, [strstudentName UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStmt, 2, [strAge UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStmt, 3, [strGender UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStmt, 4, [strDOB UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStmt, 5, [strStudentID UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStmt, 6, [strBloodGroup UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStmt, 7, [strAddress UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStmt, 8, [strClass UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStmt, 9, [strSection UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStmt, 10,[strStream UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStmt, 11,[strStuMiddleName UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStmt, 12,[strLastName UTF8String], -1, SQLITE_TRANSIENT);
if(SQLITE_DONE != sqlite3_step(updateStmt))
NSAssert1(0, @"Error while updating. '%s'", sqlite3_errmsg(database));
sqlite3_reset(updateStmt);
}
}