Android 如何使用where子句在SQLite中进行更新查询?
可能重复: 我正在使用此代码,但我希望根据我的ID进行更新Android 如何使用where子句在SQLite中进行更新查询?,android,Android,可能重复: 我正在使用此代码,但我希望根据我的ID进行更新 public void updateforgotpassword(String data) { // TODO Auto-generated method stub ContentValues forgotpass = new ContentValues(); forgotpass.put("password", data); try { db
public void updateforgotpassword(String data) {
// TODO Auto-generated method stub
ContentValues forgotpass = new ContentValues();
forgotpass.put("password", data);
try {
db.update(TABLE_NAME, forgotpass, null, null);
}
catch (Exception e)
{
String error = e.getMessage().toString();
}
}
如何执行此操作?您可以选择提供where子句 db.updateTABLE_名称,forgotpass,ID=?,新字符串[]{paramUserID}
假设行的ID存储在变量ID中,并且假设列名是标准的_ID,您可以这样更新
final String[] whereArgs = { Long.toString(id) };
db.update(TABLE_NAME, forgotpass, "_id = ?", whereArgs);
您可以始终使用rawquery方法,在该方法中可以触发普通SQL查询 或者,您可以使用SQlite提供的更新方法,其中提供两个数组,一个用于wherergs,另一个是wherevalue 使用 更新[your table]设置[your column]=行查询方法中的值 或者
参考这篇文章,你有没有试着去查?
db.update(TABLE_NAME, forgotpass, "KEY_ID = ?", whereArgs);
public boolean updateAccountData(AccountModel account) {
boolean updated = false;
openDataBase();
try {
final ContentValues values = new ContentValues();
values.put("AccountName", account.getAccountName());
values.put("Lessee", account.getLessee());
values.put("BookingRedeliveryNumber", account
.getBookingRedeliveryNumber());
values.put("SurveyorName", account.getSurveyorName());
values.put("ManufacturerName", account.getManufacturerName());
values.put("State", account.getState());
values.put("TurnInMonth", account.getTurnInMonth());
values.put("TurnInYear", account.getTurnInYear());
values.put("CscMonth", account.getCscMonth());
values.put("CscYear", account.getCscYear());
myDataBase.update(ACCOUNT_MST, values, "AccountID = "
+ account.getAccountID(), null);
updated = true;
}
return updated;
}