更新不在android中的sqlite中工作

时间:2012-03-20 10:26:28

标签: android sqlite

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();
}
}

我想更新数据库 ElectiveDataBase2 中的表 Studentprofile1 。如果学生输入他的学历,姓名,密码并点击应该在数据库中更新的提交按钮..请帮忙解决这个问题

2 个答案:

答案 0 :(得分:0)

您错过了"其中"中的学生ID参数。更新的一部分:

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

答案 1 :(得分: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 ..

你尝试这种类型的方法你的项目