android - how to update or delet from database -
i new database created simple database .please let me know how delete single row data base , how edit single row database :) in advance
void createdatabase(string time, string day,string course,string room,string syl){ database = openorcreatedatabase("newdb",mode_private, null); sql = "create table if not exists examtab (time varchar ,day varchar ,course varchar ,room varchar ,syl varchar );"; c = database.rawquery(sql, null); database.execsql(sql); string insertsql = "insert examtab values('"+time+"','"+day+"','"+course+"','"+room+"','"+syl+"');"; database.execsql(insertsql); database.close(); }
create, delete, update : sqliteopenhelper « database « android
public dbadapter(context ctx) { this.context = ctx; dbhelper = new databasehelper(context); } private static class databasehelper extends sqliteopenhelper { databasehelper(context context) { super(context, database_name, null, database_version); } @override public void oncreate(sqlitedatabase db) { try { db.execsql(database_create); } catch (sqlexception e) { e.printstacktrace(); } } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { log.w(tag, oldversion + " " + newversion + ", destroy old data"); db.execsql("drop table if exists contacts"); oncreate(db); } public long insertcontact(string name, string email) { contentvalues initialvalues = new contentvalues(); initialvalues.put(key_name, name); initialvalues.put(key_email, email); return db.insert(database_table, null, initialvalues); } public boolean deletecontact(long rowid) { return db.delete(database_table, key_rowid + "=" + rowid, null) > 0; } public cursor getallcontacts() { return db.query(database_table, new string[] { key_rowid, key_name, key_email }, null, null, null, null, null); } public cursor getcontact(long rowid) throws sqlexception { cursor mcursor = db.query(true, database_table, new string[] { key_rowid, key_name, key_email }, key_rowid + "=" + rowid, null, null, null, null, null); if (mcursor != null) { mcursor.movetofirst(); } return mcursor; } public boolean updatecontact(long rowid, string name, string email) { contentvalues args = new contentvalues(); args.put(key_name, name); args.put(key_email, email); return db.update(database_table, args, key_rowid + "=" + rowid,null)> 0; } }
Comments
Post a Comment