我的數據庫代碼如下所示。爲什麼這些值沒有被插入到數據庫中?
public void addprofileinfo(HashMap<String, String> queryValues){
SQLiteDatabase database = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("StudentName", queryValues.get("StudentName"));
values.put("RegistrationNo", queryValues.get("RegistrationNo"));
values.put("Faculty", queryValues.get("Faculty"));
values.put("TotalFeePaid", queryValues.get("TotalFeePaid"));
database.insert("FEE", null, values);
database.close();
而且活動代碼是: 保護無效的onCreate(捆綁savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.insertfield); editName =(EditText)findViewById(R.id.editTextName); editFaculty =(EditText)findViewById(R.id.editTextfaculty); editFee =(EditText)findViewById(R.id.editTexttotalfeepaid); editRegid =(EditText)findViewById(R.id.editTextid); save =(Button)findViewById(R.id.buttonsave);
addData();
}
public void addData(){
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
try{
HashMap<String, String> queryValuesMap = new HashMap<String, String>();
queryValuesMap.put("StudentName",editName.getText().toString());
queryValuesMap.put("Faculty", editFaculty.getText().toString());
queryValuesMap.put("TotalFee", editFee.getText().toString());
queryValuesMap.put("RegistrationNo", editRegid.getText().toString());
dbtools.addprofileinfo(queryValuesMap);
Toast.makeText(insertData.this, "Successful!!!", Toast.LENGTH_LONG).show();
Intent intent;
intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
dbtools.close();
insertData.this.finish();
}catch(Exception e){
Toast.makeText(insertData.this, e.getMessage(), Toast.LENGTH_LONG).show();
}}
});
成功保存的消息出現,但該值未在數據庫中找到。請說出爲什麼會發生這種情況?
謝謝你很多先生... – Niroj
你能接受這個答案和投票。 –
我做了它,但投票沒有被顯示。我認爲由於我的名譽低。 – Niroj