开发者社区> 问答> 正文

关于更新sqlite数据库的问题

需要更新detail viewcontroller中textfield的记录。但是点击了更新按钮,会更新失败。

-(IBAction)updateQuery:(id)sender
{
    sqlite3_stmt *statement;

    const char *dbpath = [databasePath UTF8String];

    if (sqlite3_open(dbpath, &Information) == SQLITE_OK)
    {
        NSString *updateSQL = [NSString stringWithFormat: @"update CONTACTS set address=\"%@\",phone=\"%@\",imageUrl=\"%@\" WHERE name=\"%@\"",daddress.text,dphone.text,durl.text,dname.text];

        const char *update_stmt = [updateSQL UTF8String];

        sqlite3_prepare_v2(Information, update_stmt, -1, &statement, NULL);

        if (sqlite3_step(statement) == SQLITE_DONE)
        {
            dstatuslabel.text=@"updated successfully";
        }
        else
        {
            dstatuslabel.text = @"Failed to update contact";
        }

        sqlite3_finalize(statement);
        sqlite3_close(Information);
    }

}

展开
收起
爵霸 2016-03-17 11:18:44 2153 0
1 条回答
写回答
取消 提交回答
  • NSString *updateSQL = [NSString stringWithFormat: @"update CONTACTS set address='%@',phone='%@',imageUrl='%@' WHERE name='%@'",daddress.text,dphone.text,durl.text,dname.text];
    2019-07-17 19:04:55
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
2022 DTCC-阿里云一站式数据库上云最佳实践 立即下载
云时代的数据库技术趋势 立即下载
超大型金融机构国产数据库全面迁移成功实践 立即下载