[英]To update the content of the table in Sqlite Database in Android
我在 Sqlite Android 應用程序中創建了一個數據庫,表中有兩個字段,即Name 和 Email 。 我想更新表的內容,我正在使用的查詢是。
db.update(TABLENAME,cv,"id=?",new String[]{String.valueOf(7)});
因為這將更新 ID 為 7 的內容,但我想通過匹配輸入的名稱來更新表。
添加另一個參數,如
db.update(TABLENAME,cv,"id=? AND Name=? ",new String[]{String.valueOf(7),NameValue});
嘗試
String where="id=? and Name=?";
db.update(TABLENAME,cv,where,new String[]{String.valueOf(7),NameValue});
在更新方法中傳遞您的字符串數組...
public int Upadte(String name_value,String email_value,String new_name) {
ContentValues value = new ContentValues();
value.put("name",new_name);
return _sqliteDB.update(TABLE_NAME ,value," NAME "+"=?"+" and "+" EMAIL "+"=?",new String[]{name_value,email_value});
}
要匹配名稱而不是 ID,只需替換whereClause
的列名稱:
db.update(TABLENAME, cv, "Name=?", new String[]{"PanKush"});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.