how to reloadData in tableView when tableview access data from database.
Posted
by Ajeet Kumar Yadav
on Stack Overflow
See other posts from Stack Overflow
or by Ajeet Kumar Yadav
Published on 2010-03-16T06:14:12Z
Indexed on
2010/03/16
6:16 UTC
Read the original article
Hit count: 226
iphone
|objective-c
I am new in iphone i am developing a application that take value from data base and display data in tableview. in this application we save data from one data table to other data table this is when add first time work and when we do second time application is crash. how to solve this problem i am not understand code is given bellow
my appdelegate code for insert value from one table to other is given bellow
-(void)sopinglist
{
//////databaseName= @"SanjeevKapoor.sqlite";
databaseName =@"AjeetTest.sqlite";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath =[documentsDir stringByAppendingPathComponent:databaseName];
[self checkAndCreateDatabase];
list1 = [[NSMutableArray alloc] init];
sqlite3 *database;
if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
if(addStmt == nil) {
///////////const char *sql = "insert into Dataa(item) Values(?)";
const char *sql = " insert into Slist select * from alootikki";
///////////// const char *sql =" Update Slist ( Incredients, Recipename,foodtype) Values(?,?,?)";
if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
}
/////for( NSString * j in k)
sqlite3_bind_text(addStmt, 1, [k UTF8String], -1, SQLITE_TRANSIENT);
//sqlite3_bind_int(addStmt,1,i); // sqlite3_bind_text(addStmt, 1, [coffeeName UTF8String], -1, SQLITE_TRANSIENT);
// sqlite3_bind_double(addStmt, 2, [price doubleValue]);
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
coffeeID = sqlite3_last_insert_rowid(database);
//Reset the add statement.
sqlite3_reset(addStmt);
// sqlite3_clear_bindings(detailStmt);
//}
}
sqlite3_finalize(addStmt);
addStmt = nil;
sqlite3_close(database);
}
And the table View code for access data from database is given bellow
SanjeevKapoorAppDelegate *appDelegate =(SanjeevKapoorAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate sopinglist];
////[appDelegate recpies];
/// NSArray *a =[[appDelegate list1] componentsJoinedByString:@","];
k= [[appDelegate list1] componentsJoinedByString:@","];
© Stack Overflow or respective owner