android - Check if value exist in SQLite. If it exists, alert the user that the value exists -
I have created a table in And the clause is executed because the cursor object will not be empty. RawQuery () always gives the cursor object, so you need to check whether one or more rows have been affected by the SQL query: If the cursor is empty, moveToFirst () returns false returns () SQLite , and I want to know that the price already exists Please check your code below:
// Check that the value exists, then the cursor checkIfist = ShoppingList.b.ro ("SELECT * FROM" + selected_spinner + "WHERE" + "ITEM_NAME =" + "'+ add_tems +"' ", tap); if (checkIfExist == null) {string insert_data =" INSERT INTO "+ selected_spinner +" (ITEM_NAME, SHOP_LIST, NUMB_ITEMS) VALUES "+" ('"+ add_tems +"', "+" '+ add_shop +', "+" '"+ Add_qua ntity + "'" + "); shoppingListDB.execSQL (insert_data);} and toast. get text (getBaseContext)," + + add_tems + "exists, toast. langtha_long). Show ();
if (checkIfExist.moveToFirst ( )) {// value exists} else {// value does not exist}
Comments
Post a Comment