Android SQLite db.update()添加值 [英] Android SQLite db.update() add values

查看:607
本文介绍了Android SQLite db.update()添加值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用方法db.update()更改表中字段的值.当我插入新值时,是否可以将其与现有值相加?

I'm using the method db.update() to change a value of a field in the table. when I insert the new value it is possible sum it with the existing?

 public void Trasf() {
String value = Scegli.getText().toString();
        cv.put(CTable.PREL, mI.getText().toString());

        SQLiteDatabase db = mHelper.getWritableDatabase();

        db.update(CTable.TABLE_NAME, cv, CTable.NO + " = ?",  new String[] { value });

        db.close();
}
    }

推荐答案

不确定要做什么,但也许:

Not exactly sure what you want to do but perhaps:

 public void Trasf() { 

        String value = Scegli.getText().toString();

        // add two strings or numbers together in the .put method
        cv.put(CTable.PREL, mI.getText().toString() + " " + oldString); // for string
        cv.put(CTable.PREL, int_new + int_old); // adding numbers

        SQLiteDatabase db = mHelper.getWritableDatabase();

        db.update(CTable.TABLE_NAME, cv, CTable.NO + " = ?",  new String[] { value });

        db.close(); }
    }

这篇关于Android SQLite db.update()添加值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆