我想更新我的database.database到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;
}
答案 0 :(得分: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"];
答案 1 :(得分:1)
更新查询错误。 它应该是这样的。
UPDATE studentsDetail
SET name=?, department=?,year=?
WHERE regno=?