2012-03-20 68 views
0
public class editprofile extends Activity { 

SQLiteDatabase db2; 
Button btnSubmit; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.pro3); 

    btnSubmit=(Button)findViewById(R.id.button1); 
    Button cancel = (Button) findViewById(R.id.buttonc); 
    Button clear = (Button) findViewById(R.id.buttoncl); 

    final EditText eid=(EditText) findViewById(R.id.editText1); 
    final EditText ename=(EditText)findViewById(R.id.editText2); 
    final EditText epass=(EditText)findViewById(R.id.editText3); 
    final EditText eyear=(EditText)findViewById(R.id.editText5); 
    final EditText edept=(EditText)findViewById(R.id.editText6); 
    final EditText eemail=(EditText)findViewById(R.id.editText7); 

    cancel.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View arg0) { 
      Intent inten=new Intent(getApplicationContext(),Elective1Activity.class); 
      startActivity(inten); 
     } 
    }); 

      try{ 
    db2=openOrCreateDatabase("ElectiveDataBase2",SQLiteDatabase.CREATE_IF_NECESSARY,null); 

    }catch(SQLException e) 
    {  
    } 
    btnSubmit.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View v) { 
      ContentValues values=new ContentValues(); 
      values.put("studentid", eid.getText().toString()); 
      values.put("studentname", ename.getText().toString()); 
      values.put("password", epass.getText().toString()); 

      if((db2.update("Studentprofile1",values,"studentid"+"=?" , null))!=-1) 
      { 
       Toast.makeText(editprofile.this, "Profile updated Successfully ", 2000).show(); 
       Intent inten=new Intent(getApplicationContext(),Elective1Activity.class); 
       startActivity(inten); 

      } 
      else 
      { 
       Toast.makeText(editprofile.this, "profile not updated", 2000).show(); 
      } 
     } 
    }); 

    clear.setOnClickListener(new Button.OnClickListener() { 
     public void onClick(View v) { 
      eid.setText(""); 
      ename.setText(""); 
      epass.setText(""); 
      edept.setText(""); 
      eyear.setText(""); 
      eemail.setText(""); 
     } 
     }); 
} 
@Override 
protected void onStop() { 
    db2.close(); 
    super.onStop(); 
} 
} 

我想更新表Studentprofile1數據庫ElectiveDataBase2。如果學生輸入他的studentid,名稱,密碼,並單擊提交按鈕,應該在數據庫中更新..請幫助解決這個問題更新SQLite中不工作在Android的

+0

什麼是錯誤您收到?你能告訴我你的logcat嗎? – 2012-03-20 10:35:15

回答

0

您在您的「where」部分缺少學生id參數:

db2.update("Studentprofile1", // table 
      values,    // values 
      "studentid"+"=?", // where clause 
      new String[] {eid.getText().toString()}) // parameters for the where clause 
+0

非常感謝Sharet ..現在工作:) :) – 2012-03-20 10:36:58

+1

如果這回答了您的問題,請接受它 - http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – MByD 2012-03-20 10:38:06

0
public long editFenceInfo(int id, String title, String area, String desc, 
      String tag) { 
     ContentValues con = new ContentValues(); 
     con.put(TITLE, title); 
     con.put(AREA, area); 
     con.put(DESCR, desc); 
     con.put(TAG, tag); 

     return myDataBase.update(MASTERFENCE_TABLE, con, KEY_ID + "=" + id, 
       null); 

    } 

HII ..

你試試這個方法,典型項目