Wednesday, 15 August 2012

Android Count records in SQL database -



Android Count records in SQL database -

on start of app im trying toast number of records in database

in main activity tried

final dbadapter db = new dbadapter(this); db.open(); cursor c = db.getasset3(null); int counter=c.getcount(); toast.maketext(getbasecontext(), counter, toast.length_long).show();

and in dbhelper have next method

public cursor getasset3(editable strname) throws sqlexception { cursor mcursor = db.rawquery("select * database_table",null); homecoming mcursor; }

the app keeps crashes on start

any ideas im going wrong

any help appreciated

mark

change

toast.maketext(getbasecontext(), counter, toast.length_long).show();

to

toast.maketext(getbasecontext(), string.valueof(counter), toast.length_long).show();

because want display int in maketext,caste string.for more info see android toast maketext

edit

and alter query like

cursor mcursor = db.rawquery("select * " + database_table,null);

where database_table name of table.

android sql count

No comments:

Post a Comment