I am trying to return a string from a database, but for some reason it looks as if the cursor cannot find the Column? I think?
This is the code im having problems with:
Cursor resultSet = myDbHelper.findUser(userName);
resultSet.moveToFirst();
String result="";
TextView t1 =(TextView)findViewById(R.id.textView);
boolean a = (resultSet != null);
boolean b = (resultSet.moveToFirst());
if(resultSet != null && resultSet.moveToFirst())
{
result = resultSet.getString(resultSet.getColumnIndex("Name"));
t1.setText("String= "+result);
}
And this is the helper method that is being called:
public Cursor findUser(String uName)
{
Cursor res = myDatabase.query("Person WHERE Name = '"+uName+"';",
null,null,null,null,null,null);
return res;
}
For some reason when im debugging the app the boolean variables i have created A becomes True and B stays false, so i know it must be an issue with the Cursor moveToFirst, but i dont know whats up? the String result also remains empty.
Can anyone help me where im going wrong. The column in the DataBase is called Name, from the Person table.
Aucun commentaire:
Enregistrer un commentaire