【问题标题】:How to use AND operator in update operation for where clause in Android Sqlite?如何在 Android Sqlite 中的 where 子句的更新操作中使用 AND 运算符?
【发布时间】:2015-03-06 09:57:50
【问题描述】:

我正在尝试更新我的表,但它给了我错误如何在 Where 子句中使用 AND 运算符进行更新?

这是我的代码;

public static void updateData(long lday, String id, String usedamount, String trashedamount) {
        // TODO Auto-generated method stub
        ContentValues updatedValues = new ContentValues();          

        updatedValues.put("usedamount", usedamount);
        updatedValues.put("trashedamount",trashedamount);

        // HERE I WANT TO USE AND OPERATOR FOR DAY AND ID
        // this and operator gives error


        db.update("info_table", updatedValues, DAY + "=" + lday AND ID + "=" + id, null);

    }

谁能帮帮我?

【问题讨论】:

  • 它不会更新这段代码 db.update("info_table", updatedValues, DAY + "=" + lday AND ID + "=" + id, null);
  • 是编译器错误吗?
  • 编辑您的问题并添加您收到的确切错误消息。
  • 我的意思是你在这里遇到什么异常?分享例外
  • 它说在这一行有多个标记 - lday 的原始类型 long 没有字段 ID

标签: android sqlite where-clause


【解决方案1】:

AND 运算符需要用引号引起来

public static void updateData(long lday, String id, String usedamount, String trashedamount) {
    ContentValues updatedValues = new ContentValues();          
    updatedValues.put("usedamount", usedamount);
    updatedValues.put("trashedamount",trashedamount);

    db.update("info_table", updatedValues, DAY + "=" + lday + " AND " + ID + "=" + id, null);
}

【讨论】:

  • 是的,这很好,但需要 9 分钟才能接受答案 :) 非常感谢。
  • @Ert 如果对您有帮助,请接受作为答案
猜你喜欢
  • 2020-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多