sqlite3 * database; sqlite3_stmt * statement; NSString * dPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: @ "UserData.sqlite"]; const char * dbpath = [dPath UTF8String]; // NSLog (@ "% @", dbpath); // UserArray = [[NSMutableArray alloc] init];
if(sqlite3_open(dbpath, &database) == SQLITE_OK)
{
NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO User (UserName,FullName,Email,PhoneNo) VALUES (\"%@\", \"%@\", \"%@\" ,\"%@\")",txtUserName.text,txtFullName.text ,txtEmail.text , txtPhoneNo.text];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(database, insert_stmt, -1, &statement, NULL);
if(sqlite3_step(statement)==SQLITE_DONE)
{
txtUserName.text=@"";
txtFullName.text=@"";
txtEmail.text=@"";
txtPhoneNo.text=@"";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Add Record" message:@"Contact Added" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
alert=nil;
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"record" message:@"record not created" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
alert=nil;
}
sqlite3_finalize(statement);
sqlite3_close(database);
}
- → I am trying to insert data into a table. The code runs correctly, but the record is not added to the table. so please help me or this problem. Thanks for your reply.
source
share