Monday, April 29, 2013

[android help] sqlite statement is ok, right?


When I use the sentence below works fine!



this.getWritableDatabase().execSQL(
"UPDATE table SET assistance =assistance + 1 WHERE alum ='Saul'");


But when I tried doing it passing a variable like this:



this.getWritableDatabase().execSQL(
"UPDATE table SET assistance =assistance + 1 WHERE alum ='"+names[i]+"'");


Don't work at all : ( it does not hive me any errors but my assistance field don't goes up by 1, by the way the statement above is inside a loop, that's because I want to update all the assistance fields that match whit my names (names[i]). Sorry for my English and please help


//edit:


so here is the method event from one activity that tigger the helper method


public void pasar(View args){



choosennames= new String[500];
for(int i=0;i

TextView viewName= (TextView) findViewById(i);
//an array names
names.add(viewName);


}

for( j = 0;j obj= name.get(j);



for(k=0;k if(obj.getId()==num.get(k))
{

choosennames[z]=obj.getText().toString();

z++;
}
}
}

z=0;
helper.open();
howmany=num.size();
helper.mod(choosennames, howmany);
helper.close();
choosennames=null;


Iterator it = numeros.iterator(); //se crea el iterador it para el array
while(it.hasNext())
System.out.println(it.next());




Intent inten = new Intent(this, MainLista.class);
this.finish();

Toast toast1 =
Toast.makeText(getApplicationContext(),
"Pase de lista exitoso : )", Toast.LENGTH_SHORT);

toast1.show();
startActivity(inten);





}


And finally this is my method "mod" inside the helpers class:


public void mod(String []names,int howmany){



for(int i=0;i System.out.println("exectSQL:"+names[i]);

System.out.println("UPDATE alumnos SET asistencia =asistencia + 1 WHERE alumno ='"+names[i]+"'");

this.getWritableDatabase().execSQL(
"UPDATE alumnos SET asistencia =asistencia + 1 WHERE alumno ='"+names[i]+"'");



}




}


.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...