i’m searching for hours now, to get a solution for this problem:
at the very beginning of my android app, a layout with buttons is shown to the user. if he clicks on the button “Tasks” a listView should pop up (another activity and layout) to show him all available Tasks, and with a click on one he can do even more things, but they’re not necessary for my problem. the point is, the app won’t get any Data out of the Database, but when I Step Into or Step Over the lines which call a method for all the DBStuff it works.
Here are the necesssary lines:
if (connection1.OpenDatabase(1, getDataBaseName()))
{
CTask = connection1.DBQueryTable(getDataBaseName(), "Tasks", TempFieldT);
CEquipment = connection1.DBQueryTable(getDataBaseName(), "Equipment", TempFieldE);
connection1.CloseDatabase();
}
so he will run over those lines, execute the lines beneath, but wont give any Data back, when i’m not supervising it with breakpoints, and the steps. when i do it, all things work the way they should.
The Database Stuff the app runs through at this place.
public Android.Database.ICursor DBQueryTable(string DataBaseName, string TableName, string[] Fields)
{
FindDBPath(DataBaseName);
Android.Database.ICursor c;
string TempF = "";
string str = "";
foreach (string n in Fields)
{ TempF += n + ","; }
SQLQuery = "SELECT " + (str = TempF.TrimEnd(',')) +" FROM " + TableName;
c = sqldTemp.RawQuery(SQLQuery, null);
return c;
}
so why do the app/compiler/debugger behave like this? are there any mistakes i did, but i can’t figure out right now?
Ps: yeah i know there is a query function, but thats not necessary here as long as it would provide a solution to my problem.
Your
DBQueryTablemethod returns a cursor. That will become invalidated as soon as you close the connection in the following line:You should keep the connection open for as long as you need the cursor. For example, you could fetch all the data from the cursor and then close the connection.