Ok, so I am clearly missing something when I look at this examples. I have the following code which keeps returning the first if statement that the item is there, but it does it on anything I query. I know they don’t exist because some of the contents I am query against aren’t even 12 characters and couldn’t possibly match. My understanding was using moveToFirst(); is either returning the result it matched, but the documentation says moveToFirst just moves it to the first row and weather it is successful. So, I think why it is always successful is because the cursor is created and the cursor does move to the first row. If that is what is going on how do I just check if a value exist within my database? Thanks for your help, not sure why this is escaping me, I had it working the other day using the same method, but maybe I changed something.
String selectQuery = "SELECT * FROM " + TABLE_NAMES + " WHERE " + COLUMN_NAME = '" + contents +"'";
Cursor cursor = myDataBase.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
contents = "The item" + contents +" is a valid.";
tv.setText(contents);
}else{
contents = "The item " + contents + " is not a valid WIC item";
tv.setText(contents);
}
close();
Your query statement has some errors in it. please replace it with the following: