开发者

how can I insert values of sqlite3 database table into NSMutableArray?

I have retrieved data from sqlite3 database table as below

NSString *name = [NSString stringWithUTF8St开发者_StackOverflow社区ring:(char *)sqlite3_column_text(compiledStatement, 0)];
NSString *price = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];

now I have an NSMutableArray named as Data, I have declared and synthesized it properly, now how can I add values into it, I tried addObject, and print in NSLog, but showing null value, while there are values in name and price?

help me out


If the array is nil, it will never accept values because it doesn't exist. Even if you synthesize a property, it doesn't mean the property gets a default object assigned to it. Somebody still has to make sure an instance of NSMutableArray exists.


NSNumber *WId;
                int temp1 = (int)sqlite3_column_int(walkstatement, 0);
                WId = [[NSNumber alloc] initWithInt:temp1];

                char *WNameCharacter;
                WNameCharacter = (char *) sqlite3_column_text(walkstatement, 1);
                NSString *WNameString = [[NSString alloc] initWithUTF8String:WNameCharacter];

NSMutableDictionary *tempWalk = [[NSMutableDictionary alloc] init];
                [tempWalk setObject:WId forKey:@"WalkId"];
                [tempWalk setObject:WNameString forKey:@"WalkName"];

            [regionWalkArray addObject:tempWalk];

This worked for me please change the variables according to your requirement..

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜