2012-03-22 52 views
1

如何在NSMutableArray中保存查詢中的值。保存查詢的值

tempQuery=[@"select * from iapp_tbl_questions where id= " stringByAppendingString:[NSString stringWithFormat:@"%d",rowid1]]; 


const char *query2=[tempQuery UTF8String]; 
if (sqlite3_prepare_v2(database,query2,-1,&statement1,NULL)==SQLITE_OK) { 
    NSLog(@"vt", vt); 
    vt=[[[Question1 alloc]init]autorelease]; 
    while (sqlite3_step(statement1)==SQLITE_ROW) { 

     vt.question=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement1,3)]; 

    } 
} 
return vt; 

謝謝...

+0

你,當你想這會得到什麼錯誤? – hchouhan02 2012-03-22 12:06:07

回答

0
const char *query2=[tempQuery UTF8String]; 
NSMutableArray *results = nil; 
if (sqlite3_prepare_v2(database,query2,-1,&statement1,NULL)==SQLITE_OK) { 
    NSLog(@"vt", vt); 
    results= [[NSMutableArray alloc]init]; 
    while (sqlite3_step(statement1)==SQLITE_ROW) { 
vt=[[[Question1 alloc]init]autorelease]; 
     vt.question=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement1,3)]; 
[results addObject:vt]; 

    } 
} 
return results; 
+0

謝謝你的回覆。我在我的應用程序中添加了上面的代碼。但如果我返回結果,它會讓我崩潰。 – user801222 2012-03-22 11:10:10

+0

你有沒有改變你的返回類型?你可以發佈在控制檯上顯示的內容嗎? – Apurv 2012-03-22 13:05:39