Venkata Venkata - 9 days ago 4x
Android Question

Error while updating the column in SQLite Database Android

I am trying to update the column in the table using update method. I am thrown syntax error like this:

SQLiteException: no such column: DataStructures (code 1): , while compiling: UPDATE tbl_courses SET checked_status=? WHERE course_name=DataStructures

Here is my Database Query:

public static final String TABLE_COURSES = "tbl_courses";
public static final String COLUMN_COURSE_ID = "_id";
public static final String COLUMN_COURSE_NAME = "course_name";
public static final String COLUMN_COURSE_SELECTED = "checked_status";
public static final String COLUMN_COURSE_CODE = "course_code";

public void updateSelectedCourseField(String courseName, String courseSelected) {
ContentValues args = new ContentValues();
args.put(COLUMN_COURSE_SELECTED, courseSelected);
database.update(TABLE_COURSES, args, COLUMN_COURSE_NAME + "=" + courseName,null);

I am trying to change checked_status value in tbl_courses where course_name = DataStructures. I am sure its in the database but its throwing me the error. please guide me through this.


I'd say DataStructures needs to be surrounded in quotes given that it is a text value, and not a table column.

So something like:

database.update(TABLE_COURSES, args, COLUMN_COURSE_NAME + "='" + courseName + "'",null);