更新SQLiteDatabase中的信息

时间:2016-12-14 12:54:47

标签: java android

我正在尝试使用sqlitedatabase更新listview上的信息,因此在我的更新类中,我收到的错误就在图片上http://prntscr.com/djbe3i

这是dbhelper方法代码:

 public int updateInformation(String old_name, String new_name,String old_hours, String new_hours, String old_department,String new_department,SQLiteDatabase sqLiteDatabase) {

    ContentValues contentValues = new ContentValues();
    contentValues.put(UserContract.NewUserInfo.Name,new_name);
    contentValues.put(UserContract.NewUserInfo.RenderedHours,new_hours);
    contentValues.put(UserContract.NewUserInfo.Department,new_department);

    String selection = UserContract.NewUserInfo.Name + " LIKE ?";
    String[] selection_args = {old_name};
    int count = sqLiteDatabase.update(UserContract.NewUserInfo.TABLE_NAME,contentValues,selection,selection_args);
    return count;

}

更新课程代码:

  public void updateContact(View view) {

    userDBHelper = new UserDBHelper(getApplicationContext());
    sqLiteDatabase = userDBHelper.getWritableDatabase();
    String name,hours,department;

    name = new_name.getText().toString();
    hours = new_hours.getText().toString();
    department = new_department.getText().toString();
int count = userDBHelper.updateInformation(search_id,NewName,NewHours,NewDepartment,sqLiteDatabase);

}
}

编辑:我将代码更改为:

public void updateContact(View view) {

    userDBHelper = new UserDBHelper(getApplicationContext());
    sqLiteDatabase = userDBHelper.getWritableDatabase();
    String name,hours,department;

    name = new_name.getText().toString();
    hours = new_hours.getText().toString();
    department = new_department.getText().toString();
    int count =  userDBHelper.updateInformation(search,name,hours,department,sqLiteDatabase);

}

我仍然得到错误,我不明白。

2ND编辑:我现在好了,我只是错误输入了字符串和我需要更新联系人的参数我将代码替换为:

 int count = userDBHelper.updateInformation(search_id,name,hours,department,sqLiteDatabase);

DBHelper.updateInformation code:

public int updateInformation(String old_name, String new_name, String new_hours,String new_department,SQLiteDatabase sqLiteDatabase)

1 个答案:

答案 0 :(得分:0)

我现在得到了我的参数不匹配,我通过将代码更改为:

来修复它
public int updateInformation(String old_name, String new_name, String new_hours,String new_department,SQLiteDatabase sqLiteDatabase)

然后更改更新类中的代码:

int count = userDBHelper.updateInformation(search_id,name,hours,department,sqLiteDatabase);