开发者

Table view sqlite data not deleting - iOS - iPad application

For some reason my data in the database is not deleting, I would be grateful if you can point out the error.

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{
NSUInteger row = [indexPath row];

    //Delete
    sqlite3_stmt *stmt2; 
    NSArray *del = [[arr objectAtIndex:row] componentsSeparatedByString:@" "];
    NSString *update1 = [NSString stringWithFormat:@"delete from survey where name='%@' and surname='%@';",[del objectAtIndex:1],[del objectAtIndex:2]];
    int x = sqlite3_prepare_v2(database, [update1 UTF8String], -1, &stmt2, nil);
    NSLog(@"x=%d",x);
    if (sqlite3_step(stmt2) != SQLITE_DONE)
        NSLog(@"Delet开发者_如何学Goion Error.");

    [arr removeObjectAtIndex:row]; 
    [tblView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

Many thanks.


Is that the data from database not deleting or data from tableview not deleting. Please confirm by checking your database(from commandline or sqlite manager).

Here Comes the possible mistakes in your code. 1) Dont pass NSString to sqlite3, pass it like this const char *query = [queryStr UTF8String]; 2) make sure that you are finalizing/committing the sqlite statement.

sqlite3_finalize(stmt)

and also close the sqlite database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜