我正在开发一个iPad应用程序,用户可以在其中添加用户数量及其详细信息。在这里,我实现了数据库,表的创建,将数据输入到表中并检索它。但我无法更新表格,
我在网上找到了一个充足的项目。通过使用它,它在我编辑页面时显示更新,但是当我重建应用程序时,它尚未更改或更新。我用Google搜索,但我找不到解决方案。
我的代码将文本发送到更新功能:
-(IBAction)btn3:(id)sender{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
//Create a Coffee Object.
Coffee *coffeeObj = [[Coffee alloc] initWithPrimaryKey:1];
coffeeObj.fname = txt1.text;
coffeeObj.lname = txt2.text;
coffeeObj.address = txv1.text;
/*NSDecimalNumber *temp = [[NSDecimalNumber alloc] initWithString:txt3.text];
coffeeObj.phone = temp;*/
coffeeObj.phone=txt3.text;
coffeeObj.email = txt4.text;
coffeeObj.notes = txv2.text;
coffeeObj.images= img.image;
coffeeObj.status=labels.text;
//[temp release];
coffeeObj.isDirty = YES;
coffeeObj.isDetailViewHydrated = NO;
//Add the object
[appDelegate saveallData:coffeeObj];
}
Here is the coding for updating the table,
- (void) saveallData {
if(isDirty) {
if(updateStmt == nil) {
const char *sql = "update ruah Set fname = ?, lname = ?, address = ?, phone = ?, email = ?, notes = ?, image = ?, status = ? Where ID = ?";
if(sqlite3_prepare_v2(database, sql, -1, &updateStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating update statement. '%s'", sqlite3_errmsg(database));
}
sqlite3_bind_text(addStmt, 1, [fname UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 2, [lname UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 3, [address UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 4, [phone UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 5, [email UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 6, [notes UTF8String], -1, SQLITE_TRANSIENT);
NSData *imgData = UIImagePNGRepresentation(self.images);
sqlite3_bind_blob(addStmt, 7, [imgData bytes], [imgData length], SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 8, [status UTF8String], -1, SQLITE_TRANSIENT);
/*
int returnValue = -1;
if(self.images != nil)
returnValue = sqlite3_bind_blob(updateStmt, 3, [imgData bytes], [imgData length], NULL);
else
returnValue = sqlite3_bind_blob(updateStmt, 3, nil, -1, NULL);*/
if(SQLITE_DONE != sqlite3_step(updateStmt))
NSAssert1(0, @"Error while updating. '%s'", sqlite3_errmsg(database));
sqlite3_reset(updateStmt);
isDirty = NO;
}
//Reclaim all memory here.
fname = nil;
price = nil;
isDetailViewHydrated = YES;
}