-1

我想更新我的数据库。数据库中的 regno 没有更新,但其他字段已更新。意味着 regno 是恒定的。

  -(BOOL) updateData:(NSString*)name
            department:(NSString*)department year:(NSString*)year
    {
        const char *dbpath = [databasePath UTF8String];
        if (sqlite3_open(dbpath, &database) == SQLITE_OK) {

            NSString *updateSQL = [NSString stringWithFormat:@"update into studentsDetail name=?, department=?, year=? where regno=? "];

            const char *update_stmt = [updateSQL UTF8String];
            sqlite3_prepare_v2(database, update_stmt, -1, &statement, NULL);
            if (sqlite3_step(statement) == SQLITE_DONE) {
                return YES;
            }
            else{
                return  NO;
            }
            sqlite3_reset(statement);
        }
        return NO;
    }
4

2 回答 2

1

像这样试试

UPDATE table_name SET column1=value1,column2=value2 WHERE some_column=some_value;


NSString *updateSQL = [NSString stringWithFormat:@"update studentsDetail SET name='%@', department='%@', year='%@' where regno='%@'",@"name",@"dept",@"year",@"regno"];
于 2013-06-05T11:58:24.320 回答
1

更新查询错误。应该是这样的。

UPDATE studentsDetail
SET name=?, department=?,year=?
WHERE regno=?
于 2013-06-05T11:59:41.867 回答