How to Insert or Update table On base of Name value in Sqlite android -
public long createcountry(string code, string name, string continent, string region) { contentvalues initialvalues = new contentvalues(); initialvalues.put(key_product_type, code); initialvalues.put(key_product_name, name); initialvalues.put(key_product_quantity, continent); initialvalues.put(key_prodcut_cost, region); return mdb.insertwithonconflict(sqlite_table, null, initialvalues, sqlitedatabase.conflict_replace); }
this insert or update function taking new row if name x alredy present in table row want should update suppose have 3 entry name column value has x,y,z suppose want call again function name x rest of value should update not should create column please me doing wrong .
there no update-or-insert function. have manually:
public void createcountry(string code, string name, string continent, string region) { contentvalues values = new contentvalues(); values.put(key_product_type, code); values.put(key_product_quantity, continent); values.put(key_prodcut_cost, region); int updated = mdb.update(sqlite_table, values, key_product_name + " = ?", new string[]{ name }); if (updated == 0) { values.put(key_product_name, name); mdb.insert(sqlite_table, null, values); } }
Comments
Post a Comment