Android Sqlite Query Detect When An Element Doesn't Exists In The Table
How can I detect when an element doesn't exist in my table? I need because I want to update/insert contacts on it. My problem it's that I want to insert a new contact by using Cont
Solution 1:
use a boolean value to check whether the contact exist or not
boolean contact = myDbHelper.checkidExitsorNot(ur table name,row name , value);
publicbooleancheckidExitsorNot(String tablename, String rowname, String id) {
String queryf = "select * from " + tablename + " where " + rowname + "='" + Integer.valueOf(id) + "'";
Cursor c = myDataBase.rawQuery(queryf, null);
if (c.getCount() == 0) {
c.close();
returntrue;
}else {
c.close();
returnfalse;
}
}
if the return is true then it does not exist if false it exist
Post a Comment for "Android Sqlite Query Detect When An Element Doesn't Exists In The Table"