2011-12-27 2 views
0

저는 SQLite에서 하나의 프로그램을 만들고 있습니다. 나는 세 가지 데이터 이름, 설명 (desc) 및 급여를 저장해야합니다. 이러한 데이터는 추가 업데이트를 위해 텍스트 필드에 표시되어야합니다.아이폰의 sqlite에서 값이 검색되지 않습니다.

(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을 보여주고있다 : 다음은 다음은 데이터베이스에 데이터를 저장하는 코드입니다

(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; 
} 

를 표시하는 내 코드입니다. 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

관련 문제