Android insert data in to database issue -
i have made database want add data database how can store value database through code.anyone me. in advance. try insert fail this
this dbhelper class.
public class fooddbhelper extends sqliteopenhelper { private static final string database_name = "pkfm.db"; private static final int database_version = 1; private static final string create_query = "create table "+ food.newdishinfo.table_name+"(" + food.newdishinfo.dish_name+" text not null," + food.newdishinfo.dish_quantity+" text not null," + food.newdishinfo.dish_calorie+" integer," + food.newdishinfo.dish_fat+" text not null," + food.newdishinfo.dish_protein+" text not null," + food.newdishinfo.dish_sugar+" text not null," + food.newdishinfo.dish_carbohydrates+" text not null);"; public fooddbhelper(context context) { super(context,database_name,null,database_version); log.e("database operation","database created / opened..."); } @override public void oncreate(sqlitedatabase db) { db.execsql(create_query); log.e("database operation","table created..."); } public void addinformations(string name ,string quantity, integer calorie, string fat , string protein,string sugar,string carbohydrates, sqlitedatabase db){ contentvalues contentvalues = new contentvalues(); contentvalues.put(food.newdishinfo.dish_name,name); contentvalues.put(food.newdishinfo.dish_quantity,quantity); contentvalues.put(food.newdishinfo.dish_calorie,calorie); contentvalues.put(food.newdishinfo.dish_fat,fat); contentvalues.put(food.newdishinfo.dish_protein,protein); contentvalues.put(food.newdishinfo.dish_sugar,sugar); contentvalues.put(food.newdishinfo.dish_carbohydrates,carbohydrates); db.insert(food.newdishinfo.table_name, null, contentvalues); log.e("database operation","one row inserted..."); } i thing not data inserted
fooddbhelper = new fooddbhelper(context); fooddbhelper.addinformations("paratha", "1 piece", 260,"8.99 g","5.16 g","2.18 g","38.94 g",sqlitedatabase);
use this.getwritabledatabase(); function hope you..
//declare variable private static final string table_friend_master = "friend_master"; private static final string create_table_friend_master = "create table if not exists " + table_friend_master + "(" + key_id + " integer primary key," + key_friend_id + " text," + key_friend_fname + " text," + key_friend_lname + " text," + key_friend_email + " text," + key_friend_mobile + " text," + key_friend_username + " text," + key_friend_country_code + " text);"; @override public void oncreate(sqlitedatabase db) { db.execsql(create_table_friend_request_master); } public int addfriend(string friendid, string friendfname, string friendlname, string friendemail, string friendmobile, string friendusername, string friendcountrycode) { synchronized (lock) { sqlitedatabase db = this.getwritabledatabase(); contentvalues values = new contentvalues(); values.put(key_friend_id, "" + friendid); values.put(key_friend_fname, "" + friendfname); values.put(key_friend_lname, "" + friendlname); values.put(key_friend_email, "" + friendemail); values.put(key_friend_mobile, "" + friendmobile); values.put(key_friend_username, "" + friendusername); values.put(key_friend_country_code, "" + friendcountrycode); // insert row int comment_row_id = (int) db.insert(table_friend_master, null, values); return comment_row_id; } }
Comments
Post a Comment