您好我试图更新数据库中的表,但是我收到了我的列不存在的错误。 该表是之前成功创建的。我能够获取信息并操纵它们但我无法更新我的编辑活动 这是我的部分代码:
//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;
}
答案 0 :(得分:2)
在您的内容值中,不应引用键名常量。例如,更改
cv.put( "KEY_JOBCOSTHOURSTREMA" , costTemp.getHourStrema());
到
cv.put( KEY_JOBCOSTHOURSTREMA, costTemp.getHourStrema());
答案 1 :(得分:2)
您可能需要删除更新名称中的引号:
我的意思是,
cv.put( KEY_JOBCOSTHOURSTREMA , costTemp.getHourStrema());
而不是
cv.put( "KEY_JOBCOSTHOURSTREMA" , costTemp.getHourStrema());
答案 2 :(得分: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;
}
答案 3 :(得分:0)
试试这个: - 删除双引号(“”)