2016-08-04 66 views
1

我想在一个表中插入一些值的database.but它显示数据未插入SQLite中目标C

我使用此代码

http://pastie.org/10929618

我上插入(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]; 
    } 
} 

Table Created

+0

你有没有检查表是否创建成功? –

+0

是HariKrishnan,检查更新后的问题 –

+0

,它使用先找到错误“NSLog(@”Error%s while prepare statement“,sqlite3_errmsg(database));” –

回答

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];