I can't Update Records in sqlite for Iphone programming
-(void)updateData:(NSInteger)ind
{
sqlite3 *database;
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
NSString *sqlStr = [NSString stringWithFormat:@"UPDATE User SET UserName=?,FullName=?,Email=? WHERE UserId=?;"];
const char *sql = [sqlStr UTF8String];
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, sql, -1, &statement, nil) != SQLITE_OK)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"DatabaseNotAvailable", @"") message:[NSString stringWithUTF8String:sqlite3_errmsg(db)]
delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
//NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
}
sqlite3_bind_text(statement, 1, [tmpun UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 2, [tmpfn UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 3, [tmpem UTF8String], -1, SQLITE_TRANSIENT);
if(SQLITE_DONE != sqlite3开发者_运维问答_step(statement))
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Records" message:@"Record Not inserted" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
alert=nil;
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Records" message:@"Record Updated" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
alert=nil;
}
sqlite3_reset(statement);
sqlite3_finalize(statement);
}
sqlite3_close(database);
}
I am trying to Update my selected record. the statement is executed properly but record is not updated into databse. ind=INdex of selected record. Thanks in advance for your response.
精彩评论