2013-08-23 67 views
-2

我有這段代碼不起作用。誰能告訴我我做錯了什麼?如下Android將變量添加到數據庫查詢

String option = names.getText().toString(); 

    Cursor c = db.rawQuery("SELECT * from numbers Where fname=option", null); 
+0

「SELECT * from numbers where fname =」+ option – KOTIOS

回答

1

變化:

Cursor c = db.rawQuery("SELECT * from numbers Where fname='"+option+"' ", null); 
+1

哈哈謝謝!我之前有''+ option +'',謝謝! – user2673161

+0

y享受!!!!!! –

1

試試這個

String query = "SELECT * from numbers Where fname='"+ option +"'";  
    database.execSQL(query); 
+0

This Works awesomely Also! – user2673161

+0

歡迎,請接受答案 –

1

更喜歡使用預處理語句與?佔位符。

String option = names.getText().toString(); 
String query = "SELECT * from numbers Where fname = ?" 

Cursor c = db.rawQuery(query, new String[] {option});