SQLite:更新无法正常工作

时间:2018-05-07 12:31:23

标签: java android sqlite

参考以下帖子,但对我没有帮助

问题是我要更改数据并点击保存按钮,它无法更新我的数据

当我打印 ID 时,它会说 NULL

更新查询

db.update(COMPANY, values, KEY_ID + " = ?",
                new String[] { String.valueOf(company.getId()) });

Java代码:

else{
    count = 0;

Company company = new Company();                                   
company.setName(etCompanyName.getText().toString().trim())                            
company.setWebsite(etWebsite.getText().toString().trim());
company.setEmail(etEmail.getText().toString().trim());                                
company.setPhoneHome(etPhoneHome.getText().toString().trim());                                    
company.setPhonePrimary(etPhonePrimary.getText().toString().trim());                                
company.setAddressLine1(etAddressLine1.getText().toString().trim());                                    

 long isUpdated = myDb.updateCompany(company);

 //Show id hear But it's null
 Log.e("TAG", "Id : " + company.getId());

 if (isUpdated != -1) {
 Toast.makeText(getApplicationContext(), "Company Update Successfully: " + isUpdated, Toast.LENGTH_SHORT).show();
 } else {
        Toast.makeText(getApplicationContext(), "Something wrong", Toast.LENGTH_SHORT).show();
         }
     Log.e("Button..."," Update Button Clickd ");
     finish();
}

当我点击“保存”按钮时,它会打印Toast信息: 每次 公司更新成功0

1 个答案:

答案 0 :(得分:0)

代码已添加..

Company company = new Company();   
company.setId(1);                            
company.setName(etCompanyName.getText().toString().trim()) 
...
long isUpdated = myDb.updateCompany(company);