WEB开发网
开发学院手机开发iPhone 开发 IOS之数据库的查找,删除,添加,更新 阅读

IOS之数据库的查找,删除,添加,更新

 2012-11-21 14:03:36 来源:WEB开发网   
核心提示:sqlite3 *db = [DB openDB];sqlite3_stmt *stmt = nil;int result = sqlite3_prepare_v2(db, [str UTF8String],-1 ,&stmt , nil);if (result == SQLITE_OK) {sqlite3_step(

sqlite3 *db = [DB openDB];
sqlite3_stmt *stmt = nil;

int result = sqlite3_prepare_v2(db, [str UTF8String],-1 ,&stmt , nil);
if (result == SQLITE_OK)
{
sqlite3_step(stmt);
}
sqlite3_finalize(stmt);



}
//根据ID删除信息
+(void)deleteByID:(int)ID
{
NSString *str = [NSString stringWithFormat:@"delete from classDB where ID = %d",ID];
sqlite3 *db = [DB openDB];
sqlite3_stmt *stmt = nil;

int result = sqlite3_prepare_v2(db, [str UTF8String], -1, &stmt, nil);

if (result == SQLITE_OK)
{
sqlite3_step(stmt);
}
sqlite3_finalize(stmt);
}
//更新
+(void)updataName:(NSString *)name phone:(NSString *)phone age:(int)age forID:(int)ID
{
NSString *str = [NSString stringWithFormat:@"update classDB set name = '%@',phone = '%@',age = %d where ID = %d",name,phone,age,ID];
sqlite3 *db = [DB openDB];
sqlite3_stmt *stmt = nil;

int result = sqlite3_prepare_v2(db, [str UTF8String], -1, &stmt, nil);

if (result == SQLITE_OK)
{
sqlite3_step(stmt);

}
sqlite3_finalize(stmt);

}
@end

上一页  1 2 3 

Tags:IOS 数据库 查找

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接