16

I want to update my database table with multiple where conditions. I already did with single where condition

db.update(TABLE_MISSING_ITEMS, values, KEY_AUTHOR + " = ?",
                new String[] { String.valueOf(items.getAuthor()) }); 

Now i want 2 where condition.

P.S :- No raw query

2

4 Answers 4

50

You can separate the different WHERE conditions with ANDlike this:

db.update(TABLE_NAME,
    contentValues,
    NAME + " = ? AND " + LASTNAME + " = ?",
    new String[]{"Manas", "Bajaj"});
Sign up to request clarification or add additional context in comments.

Comments

1

The way I solved my need

   public boolean checkHususiKayit(String baslik, String tarih) {
    boolean varMi = false;
    SQLiteDatabase database = dbHelper.getReadableDatabase();
    final String kolonlar[] = {DBHelper.COLUMN_H_ID,
            DBHelper.COLUMN_H_ID,
            DBHelper.COLUMN_H_BASLIK,
            DBHelper.COLUMN_H_TARIH,
            DBHelper.COLUMN_H_YOK_TUR,
            DBHelper.COLUMN_H_AD,
            DBHelper.COLUMN_H_WEB_ID,
            DBHelper.COLUMN_H_NUMARA,
            DBHelper.COLUMN_H_YURD_ID,
            DBHelper.COLUMN_H_YETKILI_AD,
            DBHelper.COLUMN_H_YETKILI_ID,
            DBHelper.COLUMN_H_TEL,
            DBHelper.COLUMN_H_EMAIL,
            DBHelper.COLUMN_H_ADDRESS,
            DBHelper.COLUMN_H_VAR,
            DBHelper.COLUMN_H_GOREVLI,
            DBHelper.COLUMN_H_YOK,
            DBHelper.COLUMN_H_IZINLI,
            DBHelper.COLUMN_H_HATIMDE};

    String whereClause = DBHelper.COLUMN_H_BASLIK + " = ? AND " + DBHelper.COLUMN_H_TARIH + " = ?"; // HERE ARE OUR CONDITONS STARTS
    String[] whereArgs = {baslik, tarih};


    Cursor cursor = database.query(DBHelper.TABLE_NAME_HUSUSI, kolonlar, whereClause, whereArgs, null, null, null + " ASC");
    while (cursor.moveToNext()) {
        varMi = true;
    }
    database.close();
    cursor.close();
    return varMi;
}

Comments

0

THIS CAN ALSO BE DONE LIKE THIS

public void UpdateData(int Cid,int flag,String username,String password)
    {
        SQLiteDatabase database = this.getWritableDatabase();
        ContentValues cv = new ContentValues();

          cv.put("Status",flag);//I am  updating flag here

        database.update(TABLE_NAME, cv, ""+KEY_UserName+"= '"+ username+"' AND "+KEY_CID+"='"+Cid+"'  AND "+KEY_Password+"='"+password+"'" , null);
        database.close();
    }

Comments

0

Try this simple query db.update(TABLE_FF_CHECKLIST_DATA,contentValues, "FFCHECKLISTID = ? and TASK_ID_CHK = ?" , new String[] {"EHS" , "CTO914"});

where "EHS" is value in column FFCHECKLISTID and CTO914 is value in TASK_ID_CHK.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.