I am having a problem updating my records when I edit it. I think it's on the DatabaseHandler because I don't know the right codes on how to update the database. Can someone help me fix this?
btn_Update.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
String ReportCode = tv_Code.getText().toString();
//Casting and conversion for district code
String District = spn_District.getSelectedItem().toString();
Cursor rDistrict = databaseHandler.getReport_DistrictCode(District);
String DistrictCode = rDistrict.getString(rDistrict.getColumnIndex(Constants.DISTRICT_CODE));
//Casting and conversion for province id
String Province = spn_Province.getSelectedItem().toString();
Cursor rProvince = databaseHandler.getReport_ProvinceId(Province);
String ProvinceCode = rProvince.getString(rProvince.getColumnIndex(Constants.PROVINCE_ID));
//Casting and conversion for InfoType id
String InfoType = spn_InfoType.getSelectedItem().toString();
Cursor rInfoType = databaseHandler.getReport_InfoTypeCode(InfoType);
String InfoTypeCode = rInfoType.getString(rInfoType.getColumnIndex(Constants.INFORMATIONTYPE_CODE));
int IsCompetitor = chkString;
String DateObserved = txt_Date.getText().toString();
String Remarks = txt_Remarks.getText().toString();
//UPDATE IREPORT
databaseHandler.UpdateReport(new Cons_iReport (ReportCode, InfoTypeCode, DistrictCode, ProvinceCode, DateObserved, IsCompetitor, Remarks));
Toast.makeText(getApplicationContext(), "UPDATE!", Toast.LENGTH_SHORT).show();
}
});
DatabaseHandler.java
public void UpdateReport(Cons_iReport save){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Constants.REPORT_CODE, save.getReportCode()); // Save Report Code
values.put(Constants.REPORT_DISTRICTCODE, save.getDistrict()); // Save District
values.put(Constants.REPORT_PROVINCECODE, save.getProvince()); // Save Province
values.put(Constants.REPORT_ISCOMPETITOR, save.getCompetitor()); // Save isCompetitor
values.put(Constants.REPORT_INFOTYPECODE, save.getInfoType()); // Save infoType
values.put(Constants.REPORT_DATEOBSERVED, save.getDateObserved()); // Save Date Observed
values.put(Constants.REPORT_REMARKS, save.getRemarks()); // Save Remarks
db.update(Constants.TABLE_REPORT, values, Constants.REPORT_CODE+" = ?", null);
db.close();
}
Your whereArgs
are null
db.update(Constants.TABLE_REPORT, values, Constants.REPORT_CODE+" = ?", null);
You need to supply them or it will not find any records to update.
It's the equivalent of saying "update the records where Constants.REPORT_CODE equals ... nothing". You need to tell it what REPORT_CODE to update.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.