我曾經使用這段代碼將數據寫入數據庫,但它並沒有反映到數據庫中......我不知道爲什麼?請給出您的建議!!在此先感謝..如何使用SQlite將數據寫入數據庫?
NSString* user_Name=txt_UserName.text;
NSString* password=txt_Password.text;
NSString* rePassword=txt_RePassword.text;
if ([password isEqualToString:rePassword]) {
sqlite3 *database;
sqlite3_stmt *compiledQuery;
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
const char *sqlStatement = "insert into Main values(?,?)";
sqlite3_prepare_v2(database, sqlStatement, -1, &compiledQuery, NULL);
sqlite3_bind_text(compiledQuery, 1, [user_Name UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledQuery, 2, [password UTF8String], -1, SQLITE_TRANSIENT);
if(SQLITE_DONE != sqlite3_step(compiledQuery))
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
sqlite3_finalize(compiledQuery);
sqlite3_close(database);
}
你有調試嗎?如果循環會進入內部嗎? – KingofBliss 2011-02-23 08:33:45
請使用CoreData。更強大和更友好的使用。請參閱:http://developer.apple.com/cocoa/coredatatutorial/index.html – 2011-02-23 08:37:43