1
I have the following sqlite database and works well:
db=openOrCreateDatabase("BaseDadosDB", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS tabeladados(data date,total real,descricao VARCHAR);");
I intend to return the sum of the total table between dates.
Right now I have working the search between dates, I intend the same, but now adding up the total.
Code:
if(view==btnVer) {
if (data.getText().toString().trim().length() == 0) {
alert("Erro data inicial", "Tem que inserir uma data para iniciar a pesquisa");
return;
}
if (dataa.getText().toString().trim().length() == 0) {
alert("Erro data final", "Tem que inserir uma data para iniciar a pesquisa");
return;
}
Cursor c = db.rawQuery("SELECT * from tabeladados WHERE data BETWEEN '"+data.getText()+"' AND '"+ dataa.getText()+"' ORDER BY data DESC", null);
if(c.getCount()==0) {
alert("Erro!", "Sem resultados entre as datas " + data.getText()+" E "+dataa.getText());
return;
}
StringBuffer buffer=new StringBuffer();
while(c.moveToNext())
{
buffer.append("Data:"+c.getString(0)+"\n");
buffer.append("Total Horas: "+c.getString(1)+"\n");
buffer.append("Descricão: "+c.getString(2)+"\n\n");
}
alert("Registos da data "+data.getText()+" A " + dataa.getText(), buffer.toString());
}
What I want is to return a sum and show on the screen by pressing a button for example. In other words, by pressing the button you add all the fields of the total table. Valor1+valor2+valor
.
Well what I want is to return a sum and show on the screen by pressing a button for example. In other words, pressing the button adds all the fields of the total table. Value1+value2+value
– Gabriel Silva
Good here is the code: http://35.167.140.166/site/codigo.txt I want that when pressing the button see, it is possible to obtain the total of the table "total" that is to add all the values that are inserted and show a screen message with the sum.
– Gabriel Silva