开发者

SQLite data insert not reflected in table

开发者 https://www.devze.com 2023-02-01 01:55 出处:网络
I can insert my data, but I can\'t show them in my table view. I tried [tableview reloadData] but with no success

I can insert my data, but I can't show them in my table view. I tried [tableview reloadData] but with no success

Here is my code:

-(void)gButtonTapped:(id)sender
{  


    NSLog(@"right nav bar button is  hit%@ ",storePaths);
    //[self readAnimalsFromDatabase2];

    appDelegate = (DatabaseTestAppDelegate *)[[UIApplication sharedApplication] delegate];
    sqlite3 *database;

     sqlite3_stmt *compiled_statement1;
     if(sqlite3_open([storePaths UTF8String], &database) == SQLITE_OK) {
         //const char *sqlStatement = 


         NSString *newQuery = [NSString stringWithFormat:@"insert into cat_tbl (cat_id,names,imgs) values ('12','test1','r.png')"];

        // NSString *newQuery = [NSString stringWithFormat:@"select * from list_tbl"];

        const char *sql = [newQuery cStringUsingEncoding:NSASCIIStringEncoding];


        NSLog(@"update query is %@",newQuery);

        if(sqlite3_prepare_v2(database, sql, -1, &compiled_statement1, NULL) == SQLITE_OK)
        {
            int result = sqlite3_step(compiled_statement1);
            sqlite3_reset(compiled_statement1);
            NSLog(@"result %d", result);

            if(result != SQLITE_ERROR) {
                int lastInsertId =  sqlite3_last_insert_rowid(database);
                NSLog(@"x %d", lastInsertId);
        }




        }

    }

    sqlite3_finalize(compiled_sta开发者_StackOverflow社区tement1);


    sqlite3_close(database);
    [tableView reloadData];// this is also  not working 

}


you need to update your table view data source by calling select query or update your data source by adding new values as they got inserted successfully in the data base.

0

精彩评论

暂无评论...
验证码 换一张
取 消