I am trying to update some value from sqlite database.if i update one columns value that does correctly and when i am trying update multiple value without Primary Key then my activity makes terminate.i will be grateful if could to know the reason of this error.
My Sample Code:
this code Run Well(here i have update only on column)
private void updateData(){
String fullName= editText_fullName.getText().toString();
String emailAddress= editText_emailAddress.getText().toString();
String mobileNo= editText_mobileNo.getText().toString();
String address= editText_address.getText().toString();
String voiceCode=button_tackeVoice.getText().toString();
String password=editText_password.getText().toString();
final SQLiteDatabase myDB = openOrCreateDatabase(FeedReaderDbHelper.DATABASE_NAME, MODE_PRIVATE,
null);
updateStringData(myDB, FeedReaderDbHelper.FULL_NAME, fullName);
}
private void updateStringData(SQLiteDatabase myDB,String columnName,String data){
try {
String strSQL = "UPDATE user SET "+columnName+" ='"+data+"' WHERE userName = '"+ userData.userName+"'";
myDB.execSQL(strSQL);
myDB.close();
}catch (android.database.sqlite.SQLiteConstraintException ex) {
}
}
This Code Makes Terrible:(Here i am trying to update multi column)
private void updateData(){
String fullName= editText_fullName.getText().toString();
String emailAddress= editText_emailAddress.getText().toString();
String mobileNo= editText_mobileNo.getText().toString();
String address= editText_address.getText().toString();
String voiceCode=button_tackeVoice.getText().toString();
String password=editText_password.getText().toString();
final SQLiteDatabase myDB = openOrCreateDatabase(FeedReaderDbHelper.DATABASE_NAME, MODE_PRIVATE, null);
updateStringData(myDB, FeedReaderDbHelper.FULL_NAME, fullName);
updateStringData(myDB,FeedReaderDbHelper.EMAIL_ADDRESS,emailAddress);
updateStringData(myDB,FeedReaderDbHelper.MOBILE_NO,mobileNo);
updateStringData(myDB,FeedReaderDbHelper.ADDRESS,address);
updateStringData(myDB,FeedReaderDbHelper.VOICE_CODE,voiceCode);
updateStringData(myDB,FeedReaderDbHelper.USER_PASSWORD,password);
}
private void updateStringData(SQLiteDatabase myDB,String columnName,String data){
try {
String strSQL = "UPDATE user SET "+columnName+" ='"+data+"' WHERE userName = '"+ userData.userName+"'";
myDB.execSQL(strSQL);
myDB.close();
}catch (android.database.sqlite.SQLiteConstraintException ex) {
}
}
Aucun commentaire:
Enregistrer un commentaire