2013-07-29 4 views
-1

Я знаю, что этот вопрос задавался много раз на этом сайте разными способами, но никто не работает для меня. Мне нужно обновить данные в моей базе данных из активности. Я использовал этот код:Обновление данных в базе данных SQLite

public class EditAccount extends Activity { 

private SQLiteDatabase database; 
    private MySQLiteHelper dbHelper; 
...... 
} 
public void update_acc(View view){ 
     EditText accName=(EditText)findViewById(R.id.acc_name); 
     EditText comment=(EditText)findViewById(R.id.comments); 
     String acc_name=accName.getText().toString(); 
     String comments=comment.getText().toString(); 
     Intent intent=getIntent(); 
     int id =(int) intent.getExtras().getLong("data_id"); 
     String data_id= Integer.valueOf(id).toString(); 

     //When i debug the app it comes here and stops: 
     database = dbHelper.getWritableDatabase(); 
     database.execSQL("Update comments set acc_name='"+acc_name+"', 
    comment='"+comments+"' where id="+id, null); 
     database.close(); 
     Toast.makeText(getBaseContext(), "Account updated; Acc Name:"+acc_name+" Comment:"+comments, Toast.LENGTH_LONG).show(); 
     super.onBackPressed();} 

Пожалуйста, обратите внимание и посмотреть, если есть какие-либо проблемы. Пожалуйста, помогите!

Спасибо заранее, Жду Вашего ответа ...

+1

Пожалуйста, скажите, что ошибка ваш видящий или почему он не работает, и если есть ошибка в logcat, пожалуйста, отправьте его – Boardy

+0

Вы инициализируете dbHelper? –

+0

Как получить ошибки из logCat? –

ответ

1

его сделали так:

 EditText accName=(EditText)findViewById(R.id.acc_name); 
     EditText comment=(EditText)findViewById(R.id.comments); 
     String acc_name=accName.getText().toString(); 
     String comments=comment.getText().toString(); 
     Intent intent=getIntent(); 
     int id =(int) intent.getExtras().getLong("data_id"); 
     String data_id= Integer.valueOf(id).toString(); 

     database = dbHelper.getWritableDatabase(); 
      String query="Update comments set acc_name='"+acc_name+"', comment='"+comment+"' where _id="+id; 
      database.execSQL(query); 

     //Leave a message and go back 
     Toast.makeText(getBaseContext(), "Account updated; Acc_name:"+acc_name+", Comment:"+comments, Toast.LENGTH_LONG).show(); 
     super.onBackPressed(); 
Смежные вопросы