2011-12-27 6 views
0

私は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になります。

助けてください。

+1

ブレークポイントを入れてコードをデバッグしてください – Sarah

+0

私は[チュートリアルとしてのリンク]を持っています(http://www.icodeblog.com/2008/08/19/iphone-programming-tutorial-creating-a-todo-list) -using-sqlite-part-1 /)、見てください。あなたに役立つかもしれません。ありがとう。 – Sarah

答えて

1

データベースを開いた場所がわかりません

あなたがそれを開いたことを確認してください!

私はあなたが

const char * update= [[[NSString alloc]initWithFormat:@"UPDATE EMP1 SET name ='%@',desc='%@',salary=%d WHERE empID = %d",name,desc,salary,empID] UTF8String]; 
     sqlite3_exec(db, update, nil, nil, nil); 

はそれが助け場合は私に知らせて使用しようとすることを示唆しています!

+0

ええ、私はデータベースを開いた。私は私の結果を得た。ご協力ありがとうございました。 – deepti

関連する問題