0
HII每一个无法在OBJ C到将数据插入SQLite数据库
我使用下面的方法将数据插入到数据库中,而且可以节省第一个输入的值只有所有的时间 下面的方法是所述insertUpdateDelete类
- (void) InsertRecord {
if(addStmt == nil) {
NSString *nsql = [NSString stringWithFormat:@"insert into tbl_Users(FirstName,MiddleName) Values('%@','%@')",strFirstName,strMiddleName];
const char *sql = [nsql UTF8String];
if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK)
{
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
}
}
if(SQLITE_DONE != sqlite3_step(addStmt))
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
else
//SQLite provides a method to get the last primary key inserted by using sqlite3_last_insert_rowid
intID = sqlite3_last_insert_rowid(database);
//Reset the add statement.
sqlite3_reset(addStmt);
}
通过下面的代码我正在调用该方法,tfText [0] & tfText [1]是文本字段变量,问题是,,在进入在文本字段中的一些数据后保存的每一次点击它只会将第一个输入值保存到数据库中
- (void) save_Clicked
{
iICS_testAppDelegate *appDelegate = (iICS_testAppDelegate *)[[UIApplication sharedApplication] delegate];
//Create a Items Object.
insertUpdateDelete *objInsertUpdateDelete = [[insertUpdateDelete alloc] init];
objInsertUpdateDelete.strFirstName = tfText[0].text;
objInsertUpdateDelete.strMiddleName = tfText[1].text;
[appDelegate InsertRecord:objInsertUpdateDelete];
}
任何一个可以帮助我,,,, thanx提前
非常感谢,它工作得很好,,,我的代码也是正确的认识Ÿ它没有更新的数据? – Ravi 2011-05-20 08:50:23
只需检查变量的值并调试代码...您将坚定地获得解决方案。 – SJS 2011-05-20 08:52:26
好的,试试,谢谢你 – Ravi 2011-05-20 09:12:44