Android查询sqlite数据库

时间:2011-10-26 18:45:16

标签: android sqlite

我做错了什么!?!?? 我正在尝试将一组数据添加到列表视图中。

首先我打开数据库,然后尝试获取设置, 我得到一个响应,但只有一行来自数据库,当我在sqlite浏览器中尝试时,我得到至少10行..... 无论如何我不知道这是否有意义,这里是代码:(我是新来的,请不要大笑)

顺便说一句,我在另一个listview中使用相同的方法/函数但是我的查询中没有任何WHERE,并且工作正常.... 所以我想从数据库中获取所有行,而我只得到第一行:)

感谢队友!

db.openDataBase();
Cursor c = db.getCoursesFromCountyID(countyID);
BindsimpleCursorAdapter(c);
db.close();

the getCoursesFromCountyID = 
int id = Integer.parseInt(county);
        return db.query("Courses", new String[]{KEY_course_ID, KEY_course}, KEY_county_ID + " = " + id, null, null, null, null);

And the BindsimpleCursorAdapter looks like this = 

startManagingCursor(c);
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.simpleadapter_courses, c, new String[]{DataBaseHelper.KEY_course_ID, DataBaseHelper.KEY_course}, new int[]{R.id.courseID, R.id.course});
        ListView lv = new ListView(this);
        lv = (ListView)findViewById(R.id.listViewCourses);
        lv.setAdapter(adapter);

1 个答案:

答案 0 :(得分:1)

我没有看到您的代码有任何问题,请尝试将“KEY_county_ID”添加到您的投影参数并删除选择参数以检查所有行是否确实存在。