android - SQLite adding row to table -
i'm trying add members membership table. sqlite database can add rows other tables such book table , inventory table. reason, won't add new member table, puzzles me because i'm seemingly copying same structure insert statements used add other tables. might going wrong here?
membershipadapter
public void insertentry(string firstname, string lastname, string birthday, string member_id, string email, int checkout_count, int karma_pts, string notes) { contentvalues newvalues = new contentvalues(); // assign values each row. if(firstname.equals(null)) newvalues.put("first_name", ""); else newvalues.put("first_name", firstname); if(lastname.equals(null)) newvalues.put("last_name", ""); else newvalues.put("last_name", lastname); if(birthday.equals(null)) newvalues.put("birthday", ""); else newvalues.put("birthday", birthday); if(member_id.equals(null)) newvalues.put("member_id", ""); else newvalues.put("member_id", member_id); if(email.equals(null)) newvalues.put("email", ""); else newvalues.put("email", email); if(checkout_count==0) newvalues.put("checkout_count", 0); else newvalues.put("checkout_count", checkout_count); if(karma_pts==0) newvalues.put("karma_pts", 0); else newvalues.put("karma_pts", karma_pts); if(notes.equals(null)) newvalues.put("notes", ""); else newvalues.put("notes", notes); // insert row table db.insert("membership", null, newvalues); toast.maketext(context, "member saved", toast.length_long).show(); } public int countmembers() { int count = 0; string query = "select * membership"; cursor cursor = db.rawquery(query, null); if(cursor.getcount()<1) // title not exist { cursor.close(); return 0; } while(cursor.movetonext()) { count++; } cursor.close(); return count; }
memberaddscreen
membershipadapter=new membershipadapter(this); membershipadapter=membershipadapter.open(); intent intent = getintent(); final string username = intent.getextras().getstring("username"); buttonmemberadd = (button)findviewbyid(r.id.buttonmemberadd); buttonmemberadd.setonclicklistener(new view.onclicklistener() { public void onclick(view arg0) { string firstname = inputfirstname.gettext().tostring(); string lastname = inputlastname.gettext().tostring(); string birthday = inputbirthday.gettext().tostring(); string memberid = inputmemberid.gettext().tostring(); string email = inputemail.gettext().tostring(); string notes = inputnotes.gettext().tostring(); membershipadapter.insertentry(firstname, lastname, birthday, memberid, email, 0, 0, notes); system.out.println("count members: "+membershipadapter.countmembers()); system.out.println(membershipadapter.getall()[membershipadapter.countmembers()-1][0]); toast.maketext(memberaddscreen.this, "member added", toast.length_long).show(); intent i=new intent(memberaddscreen.this,managememberscreen.class); i.putextra("username",username); startactivity(i); } });
after clicking buttonmemberadd, log shows number of rows in table still zero.
05-17 01:56:55.660: i/system.out(2995): count members: 0
Comments
Post a Comment