如何使用SQLite更新单行Android数据库

时间:2013-03-11 00:37:07

标签: android database

我使用SQLite编写了自己的数据库类,几乎所有东西都可以正常运行。但是有一个例外。我不能只更新一行,每次调用update()命令时它都会更新整列而不是我需要更改的列中的一行。

这是我要更新的代码:

DataManager dm = new DataManage (this);
Profile searchUser = dm.getProfile(i); //i is referring to an ID
searchUser.setName("Example");
dm.updateProfile(searchUser);

//This is my data manager class
public boolean updateProfile(Profile profile){
    return profileDao.update(profile);
}

//This is my data layer
public boolean update(Profile profile){
    ContentValues values = new ContentValues();
    values.put(ProfileTable.Note_USERNAME, profile.getUserName());
    values.put(ProfileTable.Note_EMAIL, profile.getEmail());
    values.put(ProfileTable.Note_PASSWORD, profile.getPassword());
    values.put(ProfileTable.Note_FNAME, profile.getfName());
    values.put(ProfileTable.Note_LNAME, profile.getlName());
    values.put(ProfileTable.Note_ADDRESS, profile.getAddress());
    return db.update(ProfileTable.TABLE_NAME, values, ProfileTable.NOTE_ID+"="+ profile.get_id(), null) > 0;        
}   

0 个答案:

没有答案