ldd379077640
聆听-花语
2016-10-27 06:41
采纳率: 34.8%
浏览 3.2k

Android SQL数据库 删除一条数据 更新一条数据 怎么弄?头疼。。。。

/**

  • 商品数据库
    */
    public class ShangPinDB {
    private static ShangPinDBHelper mShangPinDBHelper = null;
    private static ShangPinDB mInstance = null;

    /**

    • 删除一条商品???这个怎么写?
      */
      public void deleteMessage(ShangPinBean model) {
      SQLiteDatabase db = mShangPinDBHelper.getWritableDatabase();
      ContentValues values = new ContentValues();
      values.put(ShangPinDBHelper.FIELD_C_GCODE, model.getC_gcode());
      values.put(ShangPinDBHelper.FIELD_C_BARCODE, model.getC_barcode());
      values.put(ShangPinDBHelper.FIELD_C_NAME, model.getC_name());
      values.put(ShangPinDBHelper.FIELD_C_UNIT, model.getC_unit());
      values.put(ShangPinDBHelper.FIELD_C_MODE, model.getC_model());
      values.put(ShangPinDBHelper.FIELD_C_PRICE, model.getC_price());
      values.put(ShangPinDBHelper.FIELD_C_M_PRICE, model.getC_m_price());
      values.put(ShangPinDBHelper.FIELD_C_DIS_PRICE, model.getC_dis_price());
      values.put(ShangPinDBHelper.FIELD_C_STATUS, model.getC_status());
      values.put(ShangPinDBHelper.FIELD_C_PRO_STATUS, model.getC_pro_status());
      values.put(ShangPinDBHelper.FIELD_C_PROVIDER, model.getC_provider());
      values.put(ShangPinDBHelper.FIELD_C_MEM_LOST, model.getC_mem_lost());
      values.put(ShangPinDBHelper.FIELD_C_SCORE_RATE, model.getC_score_rate());
      String[] args = {String.valueOf("c_gcode")};
      db.delete(ShangPinDBHelper.TABLE_SHANGPIN_MESSAGE, "c_gcode=?", args);

      db.close();
      }

    /**

    • 更新一条商品
      */ public void update(ShangPinBean model) { SQLiteDatabase db = mShangPinDBHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(ShangPinDBHelper.FIELD_C_GCODE, model.getC_gcode()); values.put(ShangPinDBHelper.FIELD_C_BARCODE, model.getC_barcode()); values.put(ShangPinDBHelper.FIELD_C_NAME, model.getC_name()); values.put(ShangPinDBHelper.FIELD_C_UNIT, model.getC_unit()); values.put(ShangPinDBHelper.FIELD_C_MODE, model.getC_model()); values.put(ShangPinDBHelper.FIELD_C_PRICE, model.getC_price()); values.put(ShangPinDBHelper.FIELD_C_M_PRICE, model.getC_m_price()); values.put(ShangPinDBHelper.FIELD_C_DIS_PRICE, model.getC_dis_price()); values.put(ShangPinDBHelper.FIELD_C_STATUS, model.getC_status()); values.put(ShangPinDBHelper.FIELD_C_PRO_STATUS, model.getC_pro_status()); values.put(ShangPinDBHelper.FIELD_C_PROVIDER, model.getC_provider()); values.put(ShangPinDBHelper.FIELD_C_MEM_LOST, model.getC_mem_lost()); values.put(ShangPinDBHelper.FIELD_C_SCORE_RATE, model.getC_score_rate()); String[] args = {String.valueOf("c_gcode")}; db.update(ShangPinDBHelper.TABLE_SHANGPIN_MESSAGE, values, "c_gcode=?", args); db.close(); } }

这两个怎么写啊?我想在类里面直接调用这两个方法,像这种:
ShangPinDB shangpin = new ShangPinDB(getContext());
zhanShiShangPinList = shangpin.findAll();
shangpin.deleteMessage(zhanShiShangPinList.get(0));

求大神给个正确的删除 或者更新的语句

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

相关推荐