在我的應用程序中,我在SQLite數據庫中保存了賬單號碼。在添加新賬單號碼之前,如何檢查賬單號碼是否存在於數據庫中。如何檢查值已經excite或不在android中的sqlite數據庫?
我主類的代碼是,
String bill_no_excist_or_not = db.billno_exist_or_not(""+et_bill_number.getText().toString());
Log.v("Bill No", ""+bill_no_excist_or_not);
我的DB代碼,
String billno_exist_or_not(String bill_number){
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_BILL_DETAILS, new String[] { KEY_BILL_NUMBER }, KEY_BILL_NUMBER + "=?"
+ new String[] { bill_number }, null, null, null, null);
//after this i don't know how to return the values
return bill_number;
}
我不知道如何檢查這已經是可用的或者未在DB值。任何人都知道,請幫我解決這個問題。
這裏我不是清楚的瞭解,請解釋一下我在這個'if(c.getCount()!= 0) number = c.getCount(); '代碼。 – Yugesh 2013-04-25 06:53:42
如果您的查詢成功運行並找到匹配結果,則c.getCount返回匹配結果的數量...因此,我們可以得出結論,在數據庫中有一些記錄.. – 2013-04-25 07:10:47
好的謝謝Chirag Raval。 – Yugesh 2013-04-25 07:18:27