0
我現在在SQLite中做一個程序。我必須保存三個數據名稱,說明(desc)和薪水。之後,這些數據必須顯示在文本字段中以供進一步更新。下面是我用來顯示價值不是從iPhone中的數據庫中檢索iphone
(UITableViewCell *)tableView:(UITableView *)tblView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
switch(indexPath.section) {
case 0:
cell.text = empObj.name;
break;
case 1:
cell.text = [NSString stringWithFormat:@"%@", empObj.desc];
break;
case 2:
cell.text = [NSString stringWithFormat:@"%@", empObj.salary];
break;
}
return cell;
}
代碼下面是在數據庫中保存數據的代碼:
(void) saveAllData {
if(isDirty) {
if(updateStmt == nil) {
const char *sql = "update EMP1 Set name = ?,desc=?, salary = ? Where empID = ?";
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, [name UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStmt, 2, [desc UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_double(updateStmt, 3, [salary doubleValue]);
sqlite3_bind_int(updateStmt, 4, empID);
if(SQLITE_DONE != sqlite3_step(updateStmt))
NSAssert1(0, @"Error while updating. '%s'", sqlite3_errmsg(database));
sqlite3_reset(updateStmt);
isDirty = NO;
}
//Reclaim all memory here.
[name release];
name = nil;
[desc release];
desc = nil;
[salary release];
salary = nil;
isDetailViewHydrated = NO;
}
但這樣的描述(DESC)是顯示null
。如果我編輯desc
變量並保存,則顯示。但如果我關閉程序然後重新打開它,那麼詳細描述部分描述(desc)值即將到來null
。
請幫忙。
把斷點和調試你的代碼 – Sarah 2011-12-27 05:40:53
我得到了一個[鏈接作爲教程](http://www.icodeblog.com/2008/08/19/iphone-programming-tutorial-creating-a-todo-list -using-sqlite-part-1 /),看一看。可能對你有幫助。謝謝。 – Sarah 2011-12-27 09:27:20