Varinder Singh Varinder Singh - 4 months ago 11
iOS Question

Data Not inserted In Sqlite objective c

I want to insert some values in a table of database.but it is showing (NULL) on insertion

I am using This code

http://pastie.org/10929618

I have used this Link for Reference
http://www.tutorialspoint.com/ios/ios_sqlite_database.htm

//Insert Method

-(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

Answer

You are missing the column value.

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