How to use th SUM function to return the values from sqlite DB in android? -


in application, store amount details of company in sq lite db.for example om first position of db in name column-company 1,total column - 400,second position of db in name column-company 2,total column - 800,third position of db in name column-company 1,total column - 500.how sum company 1 details return total amount.

my main coding is,

string str = db.company_amount("company 1"); log.v("total", ""+str); 

my db coding is,

string company_amount(string name){  sqlitedatabase db = this.getreadabledatabase();  string s = ""; cursor cursor = db.rawquery("select sum(key_amount) table_bill_details = ?", new string[] {string.valueof(name)});  if (cursor != null) {      if (cursor.movetonext()) {         s = cursor.getstring(1);         return cursor.getstring(1);     }     cursor.close();  }  return s; } 

it shows error,i don't know how return values.can 1 know please me solve problem.

my logcat error

04-25 14:54:06.701: e/androidruntime(2776): fatal exception: main 04-25 14:54:06.701: e/androidruntime(2776): java.lang.runtimeexception: unable start activity   componentinfo{invoicebill.details/invoicebill.details.total_company_details}:                  android.database.sqlite.sqliteexception: near "=": syntax error: , while compiling: select sum(key_amount) table_bill_details = ? 

sqlitedatabase db = getreadabledatabase();     string sql = "select sum(key_amount) table_bill_details name = ?"; long sum = android.database.databaseutils.longforquery(db, sql, new string[]{name}); 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -