更新函数在调用时崩溃程序

时间:2016-08-09 00:01:59

标签: android sql database runtime-error

这是我的更新功能,但每当我打电话来更新ID时它都会崩溃。

public boolean UpdateData(String ID, String First, String Last, String MAKE, String MODEL, String Cost) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues cv = new ContentValues();
        cv.put(ID, ID);
        cv.put(CUSTOMER_FIRST_NAME, First);
        cv.put(CUSTOMER_LAST_NAME, Last);
        cv.put(CAR_MAKE, MAKE);
        cv.put(CAR_MODEL, MODEL);
        cv.put(COST, Cost);
        db.update(Table_name, cv, "ID = ?", new String[]{ID});
        return true;

例如,如果我正在更新id 2,则会导致此错误

Process: mbl402.phoenix.edu.week4appgk5343, PID: 3983
android.database.sqlite.SQLiteException: near "2": syntax error (code 1): , while compiling: UPDATE CUSTOMER_TABLE SET  2=?,Customer_First_Name=?,CAR_MAKE=?,Cost=?,CAR_MODEL=?,Customer_Last_Name=? WHERE ID = ?

1 个答案:

答案 0 :(得分:0)

弄清楚我必须拿出线 cv.put(ID,ID);