2011-04-21 52 views
0
c=MyDB.rawQuery("SELECT Distance FROM " + Table1 + 
     " WHERE Source = '" + source + "'", null); 

distance = c.getFloat(c.getColumnIndex("Distance")); 

数据库中的距离值为2.3。但是,当我在屏幕上显示它的值时,距离值显示为0.使用SQLite获得的错误值

+0

缺少分号关闭它结束了吗? – Blundell 2011-04-21 10:08:22

回答

2

您已完成c.moveToFirst();?如果你还没有数据将被提取。

+0

非常感谢。我错过了那部分代码。 – 2011-04-21 10:20:26

+1

不要忘记注册并接受答案。 – 2011-04-21 10:23:02

1

使用

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")); 

} 
+0

类型SQLiteDatabase中的方法query(String,String [],String,String [],String,String,String)不适用于参数(String,String [],String [],String [],null, null,null) 这是我得到的错误。 – 2011-04-21 10:16:47

+0

WHERE Source ='“+ source +”'“<<该行错误,应该是source =”'“+ source +”'“....不包含关键字where – Hades 2011-04-21 10:30:02