0
嘿傢伙這是我的代碼來比較名稱與數據庫中已有的東西。但是,getcount始終返回0。任何幫助?謝謝 !!getcount返回0
public String checkUserName(SQLiteDatabase db, String enteredName)
{
String selectionArgs[] = new String[1];
selectionArgs[0] = enteredName;
Cursor cursor = db.rawQuery("select * from table1 where user=?", selectionArgs);
cursor.moveToFirst();
return Integer.toString(cursor.getCount());
}
我用它來調用上面的函數的代碼是:
Intent intent = getIntent();
TextView tv1 = new TextView(this);
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE)
tv1.setText(db.checkUserName(db.getWritableDatabase(), message));
relativeLayout.addView(tv1)
DB快照鏈接:http://i.stack.imgur.com/LnTbl.jpg
沒有必要moveToFirst,你可以直接從光標檢查getlount – AlexBcn
@AlexBcn - 嗯只是注意到,即使我刪除它雖然getcount返回0 –
代碼似乎很好。確保你的表實際上包含這些數據,並檢查enteredName是否完全匹配。 –