sqlite3 * database; sqlite3_stmt *語句; 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)
{
[email protected]"";
[email protected]"";
[email protected]"";
[email protected]"";
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;
}
// Release the compiled statement from memory
sqlite3_finalize(statement);
sqlite3_close(database);
}
- >>我試圖插入數據到表中。該代碼正確執行,但記錄不會添加到表中。所以請幫助我或這個問題..謝謝你的迴應。
如何在此代碼中執行提交。 – Sam007 2011-02-03 20:12:27