我想在数据库表中插入一些值。但它在插入时显示(NULL)
我正在使用此代码
我使用此链接作为参考 http://www.tutorialspoint.com/ios/ios_sqlite_database.htm
//插入方法
-(void)SaveAction{
BOOL success = NO;
NSString *alertString = @"Data Insertion failed";
success = [[DBManager getSharedInstance]saveData:@"100" username:@"byname" type:@"one2one" user_to:@"144" user_from:@"145" timestamp:@"42015"];
if (success == NO) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:
alertString message:nil
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
答案 0 :(得分:0)
您缺少列值。
// you are passing the value use below method but dnt have "message1" column value
success = [[DBManager getSharedInstance]saveData:@"100" username:@"byname" type:@"one2one" user_to:@"144" user_from:@"145" timestamp:@"42015"];
// compare the below query
NSString *insertSQL = [NSString stringWithFormat:@"insert into chatDetail (chat_id,username, type, message1,user_to,user_from,timestamp) values (\"%ld\",\"%@\", \"%@\", \"%@\",\"%@\",\"%@\")",(long)[chat_id integerValue], username, type, user_to,user_from,timestamp];