0

您好,我正在尝试更新数据库中的表,但我收到我的列不存在的错误。该表之前已成功创建。我能够获取信息并对其进行操作,但我无法在我的编辑活动中更新这是我的部分代码:

//job_cost table------------------------------------------------
    public static final String KEY_JOBCOSTID = "jobcostID";
    public static final String KEY_JOBCOSTHOURSTREMA = "jobcostHourStrema";
    public static final String KEY_JOBCOSTGROUNDTYPE = "jobcostGroundType";
    public static final String KEY_JOBCOSTPETROL = "jobcostPetrol";
    public static final String KEY_JOBCOSTOIL = "jobcostOil";
    public static final String KEY_JOBCOSTMAINTENANCE = "jobcostMaintenance";
    public static final String KEY_JOBCOSTOTHEREXPENSES = "jobcostOtherExpenses";
    public static final String KEY_JOBCOSTFINAL = "jobcostFinal";

db.execSQL("CREATE TABLE " + DATABASE_JOBCOSTTABLE + "("
                    + KEY_JOBCOSTID + " INTEGER PRIMARY KEY autoincrement , "
                    + KEY_JOBCOSTHOURSTREMA + " DOUBLE , "
                    + KEY_JOBCOSTGROUNDTYPE + " TEXT , "
                    + KEY_JOBCOSTPETROL + " DOUBLE , "
                    + KEY_JOBCOSTOIL + " DOUBLE , "
                    + KEY_JOBCOSTMAINTENANCE + " DOUBLE , "
                    + KEY_JOBCOSTFINAL + " DOUBLE , "
                    + KEY_JOBCOSTOTHEREXPENSES + " DOUBLE  )");
        }

public boolean updateJobCost(Cost costTemp,String jobForEdit){
        ContentValues cv = new ContentValues();

        cv.put( "KEY_JOBCOSTHOURSTREMA" , costTemp.getHourStrema());
        cv.put( "KEY_JOBCOSTGROUNDTYPE" , costTemp.getGroundType());
        cv.put( "KEY_JOBCOSTPETROL" , costTemp.getPetrol());
        cv.put( "KEY_JOBCOSTOIL" , costTemp.getOil());
        cv.put( "KEY_JOBCOSTMAINTENANCE" , costTemp.getMaintenance());
        cv.put( "KEY_JOBCOSTOTHEREXPENSES" , costTemp.getOtherExpenses());
        cv.put( "KEY_JOBCOSTFINAL" , costTemp.getCost());
        //cv.put(key, value)
        ourDatabase.updateWithOnConflict(DATABASE_JOBCOSTTABLE, cv, KEY_JOBCOSTID + "=" + jobForEdit, null, DATABASE_VERSION);
        return false;
    }
4

4 回答 4

2

在您的内容值中,不应引用键名常量。例如,改变

 cv.put( "KEY_JOBCOSTHOURSTREMA" , costTemp.getHourStrema());

 cv.put( KEY_JOBCOSTHOURSTREMA, costTemp.getHourStrema());
于 2013-10-11T11:36:20.917 回答
2

您可能需要删除更新名称中的引号:

我是说,

cv.put( KEY_JOBCOSTHOURSTREMA , costTemp.getHourStrema());

代替

cv.put( "KEY_JOBCOSTHOURSTREMA" , costTemp.getHourStrema());

于 2013-10-11T11:37:15.637 回答
1

您使用的是键值而不是列名。将代码更改为:

public boolean updateJobCost(Cost costTemp,String jobForEdit){
    ContentValues cv = new ContentValues();

    cv.put( KEY_JOBCOSTHOURSTREMA , costTemp.getHourStrema());
    cv.put( KEY_JOBCOSTGROUNDTYPE , costTemp.getGroundType());
    cv.put( KEY_JOBCOSTPETROL , costTemp.getPetrol());
    cv.put( KEY_JOBCOSTOIL , costTemp.getOil());
    cv.put( KEY_JOBCOSTMAINTENANCE , costTemp.getMaintenance());
    cv.put( KEY_JOBCOSTOTHEREXPENSES , costTemp.getOtherExpenses());
    cv.put( KEY_JOBCOSTFINAL , costTemp.getCost());
    //cv.put(key, value)
    ourDatabase.updateWithOnConflict(DATABASE_JOBCOSTTABLE, cv, KEY_JOBCOSTID + "=" + jobForEdit, null, DATABASE_VERSION);
    return false;
}
于 2013-10-11T11:37:33.347 回答
0

试试这个: - 删除双引号(“”)

 cv.put( KEY_JOBCOSTHOURSTREMA , costTemp.getHourStrema());
    cv.put( KEY_JOBCOSTGROUNDTYPE , costTemp.getGroundType());
    cv.put( KEY_JOBCOSTPETROL , costTemp.getPetrol());
    cv.put( KEY_JOBCOSTOIL , costTemp.getOil());
    cv.put( KEY_JOBCOSTMAINTENANCE , costTemp.getMaintenance());
    cv.put( KEY_JOBCOSTOTHEREXPENSES , costTemp.getOtherExpenses());
    cv.put( KEY_JOBCOSTFINAL , costTemp.getCost());
于 2013-10-11T11:48:44.390 回答