[英]Update a row in sqlite table Android
I am trying to update 2 values in a row of table which also contain another 7 values which is not changed. 我试图更新表中的行中的2个值,该表还包含其他7个未更改的值。 Code for update:
更新代码:
public int UpdateItem(int tableId, String itemname, String modifiername, int count, double totalPrice) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(DbSchema.ORDERED_ITEM_QUANTITY, count);
values.put(DbSchema.ORDERED_ITEM_TOTAL_PRICE, totalPrice);
return db.update(DbSchema.KOT_TABLE, values, DbSchema.TABLE_ID + " = " + tableId +
" AND " + DbSchema.ORDERED_ITEM_NAME + " = '" + itemname +
"' AND " + DbSchema.ORDERED_ITEM_MODIFIER_NAME + " = '" + modifiername + "'",
null);
}
Call for update is from a itemclick of an Adapter: 调用更新来自适配器的itemclick:
holder.incrementButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int count = Integer.parseInt(holder.itemCount.getText().toString());
holder.itemCount.setText("" + (count + 1));
filteresKotItemArrayList.get(position).setOrderedItemQuantity(count + 1);
Double totalPrice = Double.parseDouble(holder.totalAmount.getText().toString()) + kotItem.getOrderedItemBasePrice();
holder.totalAmount.setText(String.valueOf(totalPrice));
filteresKotItemArrayList.get(position).setOrderedItemTotalPrice(totalPrice);
dbOpenhelper.UpdateItem(kotItem.getTableId(), kotItem.getOrderedItemnme(), kotItem.getOrderedItemModifierName(), (count + 1), totalPrice);
notifyDataSetChanged();
}
});
In model class it is working but db it is not updating. 在模型类中,它正在工作,但在数据库中,它没有更新。 When i reopen the current list by updating db its not updated their.
当我通过更新数据库重新打开当前列表时,其未更新。
kotItemList = dbOpenhelper.getKOTList(tableId);
No error is showing. 没有错误显示。 How can i update that row also use query to do that but no Result.
我如何更新该行还使用查询来做到这一点,但没有结果。
String strSQL = "UPDATE " + DbSchema.KOT_TABLE + " SET " +
DbSchema.ORDERED_ITEM_QUANTITY + " = " + count + ","
+ DbSchema.ORDERED_ITEM_TOTAL_PRICE + " = " + totalPrice +
" WHERE " + DbSchema.TABLE_ID + " = " + tableId +
" AND " + DbSchema.ORDERED_ITEM_NAME + " = '" + itemname +
"' AND " + DbSchema.ORDERED_ITEM_MODIFIER_NAME + " = '" + modifiername + "'";
db.execSQL(strSQL);
Check your where clause that cause an issue. 检查导致问题的where子句。 for a try just update values using only where clause --- DbSchema.ORDERED_ITEM_NAME = "xyz".
尝试只使用where子句--- DbSchema.ORDERED_ITEM_NAME =“ xyz”更新值。 Also check that DbSchema.ORDERED_ITEM_NAME value is exists in your table
还要检查表中是否存在DbSchema.ORDERED_ITEM_NAME值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.