2011-06-02 65 views
0

我遇到了数据库中的数据问题。 我试图把一些数据,并显示在我的微调。但我有空的微调。 我真的不明白我错在哪里。 这里是我的代码数据有问题

public void onCreate(SQLiteDatabase db) { 
    db.execSQL("CREATE TABLE "+TABLE_NAME+" ("+colCountryID+ " INTEGER PRIMARY KEY , "+ 
      colCountryName+ " TEXT)"); 
    InsertCountry(db); 
} 

@Override 
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
    db.execSQL("DROP TABLE IF EXISTS" + TABLE_NAME); 
    onCreate(db); 
} 
public Cursor getAllDepts() { 
    SQLiteDatabase db = this.getReadableDatabase(); 
    Cursor cur = db.rawQuery("SELECT " + colCountryID + " as _id, " + colCountryName + " from " + TABLE_NAME, new String[] {}); 
    return cur; 
} 

public void InsertCountry(SQLiteDatabase db) { 
    ContentValues cv = new ContentValues(); 
    cv.put(colCountryID, 1); 
    cv.put(colCountryName, "GB"); 
    db.insert(TABLE_NAME, null, cv); 
    Log.w(TABLE_NAME, "insert"); 

} 

而且

database = new DBTestHelper(this); 

Cursor c=database.getAllDepts(); 
startManagingCursor(c); 


SimpleCursorAdapter ca=new SimpleCursorAdapter(this,R.layout.dvdfg, c, new String [] {DBTestHelper.colCountryName,"_id"}, new int []{R.id.text}); 
//ca.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
counry.setAdapter(ca); 

回答

0
Cursor cur = db.rawQuery("SELECT " + colCountryID + " as _id, " + colCountryName + " from " + TABLE_NAME, new String[] {}); 

觉得奇怪,我试图传递一个空数组作为最后一个参数

Cursor cur = db.rawQuery("SELECT " + colCountryID + " as _id, " + colCountryName + " from " + TABLE_NAME, null); 
+0

它没有帮助:( – Viktoriya 2011-06-02 15:06:49

+0

你是否尝试自己读光标,而不是让微调执行它。在getAllDepts中循环光标。 – Snicolas 2011-06-02 15:10:14

+0

对不起,我不了解你。你能解释一下吗? – Viktoriya 2011-06-02 15:12:43