私はSQLiteで1つのプログラムをやっています。私は3つのデータ名、説明(desc)と給料を保存しなければなりません。その後、これらのデータは更なる更新のためにテキストフィールドに表示されなければなりません。以下は、以下iphoneのsqliteの値がデータベースから取得されない
(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
私は[チュートリアルとしてのリンク]を持っています(http://www.icodeblog.com/2008/08/19/iphone-programming-tutorial-creating-a-todo-list) -using-sqlite-part-1 /)、見てください。あなたに役立つかもしれません。ありがとう。 – Sarah