SQLite数据库更新查询与Android中的多个条件

时间:2014-09-09 05:38:33

标签: android database sqlite android-sqlite

我想用多个where条件更新我的数据库表。我已经做过单身条件

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

现在我想要2条件。

P.S: - 没有原始查询

4 个答案:

答案 0 :(得分:36)

您可以将不同的WHERE条件与AND分开,如下所示:

db.update(TABLE_NAME,
    contentValues,
    NAME + " = ? AND " + LASTNAME + " = ?",
    new String[]{"Manas", "Bajaj"});

答案 1 :(得分:0)

这也可以像这样

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();
    }

答案 2 :(得分:0)

尝试这个简单的查询 db.update(TABLE_FF_CHECKLIST_DATA,contentValues,“FFCHECKLISTID =?和TASK_ID_CHK =?”,new String [] {“EHS”,“CTO914”});

其中“EHS”是FFCHECKLISTID列中的值,CTO914是TASK_ID_CHK中的值。

答案 3 :(得分:0)

我解决了我的需要

   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;
}