2015-12-14 17 views
0
SQLiteDatabase database = this.getReadableDatabase(); 
     Cursor cursor = database.rawQuery(selectAll + DatabaseSchema.Vehicles.TABLE_NAME + " where " + DatabaseSchema.Vehicles.COLUMN_ID + "=" + id, null); 
     cursor.moveToFirst(); 

這裏,selectAll = "select * from "COLUMN_ID是int數據類型。此代碼每次都會返回一個空遊標。即使數據插入表中。 當我運行查詢只有「select * from tablename」。它給了我數據。如何在SQLite,Android中的整數字段執行選擇查詢?

+0

是否有具有價值在其COLUMN_ID外地傳入ID的任何行? –

+0

我沒有完全明白你的問題。 COLUMN_ID是int主鍵。它是自動遞增的。 – ndkcha

+1

你有一行COLUMN_ID == ID嗎? – Blackbelt

回答

1

我覺得你的問題是,當你與cursor.moveToFirst(); accesing試試這個:

SQLiteDatabase database = this.getReadableDatabase(); 
Cursor cursor = database.rawQuery(selectAll + DatabaseSchema.Vehicles.TABLE_NAME + " where " + DatabaseSchema.Vehicles.COLUMN_ID + "=" + id, null); 
if (cursor != null && cursor.moveToFirst()) { 
    do { 
    //Do your stuff! 
    } while (cursor.moveToNext()); 
} 
cursor.close(); 
+0

當我試圖檢索由「文本」作爲數據庫中的數據類型的列,它返回結果的行。但在「int」作爲數據類型的情況下,它會給我空遊標。 – ndkcha