database - Android Studio SQLiteDatabase - no such column -
this question has answer here:
i have started working sqlite database , have ran problem. whenever try update or delete data, app crashes , displays , error "no such column: s_id". have tried fix days have had no luck. appreciate if tell me problem , why occurring. thank you.
here database:
public class databasehelper extends sqliteopenhelper{ public static final string database_name = "sqlite.db"; public static final int version = 1; public static final string table_name = "tbl_reminder"; public static final string s_id = "s_id"; public static final string s_title = "s_title"; public static final string s_date = "s_date"; public databasehelper(context context) { super(context, database_name, null, version); } @override public void oncreate(sqlitedatabase db) { string create_table = "create table " + table_name + " (id integer primary key autoincrement, " + s_id +" text)"; db.execsql(create_table); } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { db.execsql("drop_table" + table_name); oncreate(db); } public void insertdata (string s_title){ contentvalues contentvalues = new contentvalues(); contentvalues.put(s_title, s_title); sqlitedatabase sqlitedb = this.getwritabledatabase(); sqlitedb.insert(table_name, null, contentvalues); sqlitedb.close(); } public arraylist<viewholderhelper> getalldata() { arraylist<viewholderhelper> list = new arraylist<>(); string sql = "select * " + table_name; sqlitedatabase db = this.getwritabledatabase(); cursor cursor = db.rawquery(sql, null); if (cursor.movetofirst()) { { viewholderhelper vhh = new viewholderhelper(); vhh.setid(cursor.getint(0) + ""); vhh.settitle(cursor.getstring(1)); list.add(vhh); } while (cursor.movetonext()); } return list; } public void updatedata(int id, string title){ contentvalues contentvalues = new contentvalues(); contentvalues.put(s_title, title); sqlitedatabase sqlitedb = this.getwritabledatabase(); sqlitedb.update(table_name, contentvalues, s_id + "=" + id, null); sqlitedb.close(); } public void deletedata(int id){ sqlitedatabase sqlitedb = this.getwritabledatabase(); sqlitedb.delete(table_name, s_id + "=" + id, null); sqlitedb.close(); } }
here error displayed:
fatal exception: main process: json.google_services.newreminderapp, pid: 23419 android.database.sqlite.sqliteexception: no such column: s_id (code 1): , while compiling: update tbl_reminder set s_title=? s_id=1
delete example
public void deletuser(string name) { string selection = newuserinfo.user_name + " ?"; string[] selection_args = {name}; getwritabledatabase().delete(newuserinfo.table_name, selection, selection_args); }
update example
public int updateinformation(string oldname, string newname, string newage, string newmobile, int newgender) { string selection = newuserinfo.user_name + " ?"; string[] selection_args = {oldname}; contentvalues contentvalues = new contentvalues(); contentvalues.put(newuserinfo.user_name, newname); contentvalues.put(newuserinfo.user_age, newage); contentvalues.put(newuserinfo.user_mob, newmobile); contentvalues.put(newuserinfo.user_gender, newgender); int count = getwritabledatabase().update(newuserinfo.table_name, contentvalues, selection, selection_args); return count; }
Comments
Post a Comment