EDIT, Changed the code slightly based on answers below, but still haven\'t got it working. I also added a log message to tell me if getCount was returning > 0, and i
Use this:
public Boolean doesRecordExist(String TableName, String ColumnName, String ColumnData) {
String q = "Select * FROM "+TableName+" WHERE "+ColumnName+"='"+ColumnData+"';";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(q, null);
if (cursor.moveToFirst()) {
return true;
} else {
return false;
}
}
if (doesRecordExist("student", "name", "John") == true)
{
//Do Something
} else { //Do something
}
Modify This according to your usage:
String q = "Select * FROM "+TableName+" WHERE "+ColumnName+"='"+ColumnData+"';";