c=MyDB.rawQuery("SELECT Distance FROM " + Table1 +
" WHERE Source = '" + source + "'", null);
distance = c.getFloat(c.getColumnIndex("Distance"));
數據庫中的距離值爲2.3。但是,當我在屏幕上顯示它的值時,距離值顯示爲0.使用SQLite獲得的錯誤值
c=MyDB.rawQuery("SELECT Distance FROM " + Table1 +
" WHERE Source = '" + source + "'", null);
distance = c.getFloat(c.getColumnIndex("Distance"));
數據庫中的距離值爲2.3。但是,當我在屏幕上顯示它的值時,距離值顯示爲0.使用SQLite獲得的錯誤值
您已完成c.moveToFirst();
?如果你還沒有數據將被提取。
非常感謝。我錯過了那部分代碼。 – 2011-04-21 10:20:26
不要忘記註冊並接受答案。 – 2011-04-21 10:23:02
使用
c=MyDB.query(Table1,new String[]{Distance}, "Source = ?", new String[]{source},null,null, null);
if(c != null && c.moveToFirst()) {
distance = c.getFloat(c.getColumnIndex("Distance"));
}
類型SQLiteDatabase中的方法query(String,String [],String,String [],String,String,String)不適用於參數(String,String [],String [],String [],null, null,null) 這是我得到的錯誤。 – 2011-04-21 10:16:47
WHERE Source ='「+ source +」'「<<該行錯誤,應該是source =」'「+ source +」'「....不包含關鍵字where – Hades 2011-04-21 10:30:02
缺少分號關閉它結束了嗎? – Blundell 2011-04-21 10:08:22