0

I am using query for search but i don't understand why one code is work and another one not work ?!

this is working:

          String selectQuery = "SELECT  * FROM " + TABLE_Soras
                               +" WHERE "+KEY_SoraName+" LIKE '%"+soraName+"%'";
          Cursor cursor = db.rawQuery(selectQuery,null);

but this isn't get any result:

    Cursor cursor = db.query(TABLE_Soras, new String[]{
             KEY_SORA_NO, KEY_SoraName}, KEY_SoraName + "=?",
            new String[]{soraName}, null, null, null, null);*/
amorenew
  • 10,760
  • 10
  • 47
  • 69

3 Answers3

2

Because in second case % is not appended into value and you didn't add LIKE clause into query. You need to use this:

KEY_SoraName + " like ?", new String[] {"%" +soraName + "%"} ...
Simon Dorociak
  • 33,374
  • 10
  • 68
  • 106
0

Try this

Cursor cursor = db.query(TABLE_QuranSoras, new String[]{
             KEY_SORA_NO, KEY_SoraName}, KEY_SoraName+" LIKE '%"+soraName+"%'", null, null, null, null);
Sanket Shah
  • 4,352
  • 3
  • 21
  • 41
0
Cursor cursor = your_database.query(MY_TABLE, new String[] {"first_column","second_column"},your_column + " LIKE '%"+your_criteria+"%'", null, null, null, null);

Try something like this and it will probably work!

Pavlos
  • 2,183
  • 2
  • 20
  • 27