I am having a problem with navigating between a MainPage and a details Page.
On the main page the code looks like this:
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
State.Clear();
List<Level> lst = new List<Level>();
using (SqliteCommand selectCmd = Constants.conn.CreateCommand())
{
Constants.conn.Open();
selectCmd.Transaction = Constants.conn.BeginTransaction();
selectCmd.CommandText = " SELECT * FROM Levels";
using (SqliteDataReader reader = selectCmd.ExecuteReader())
{
while (reader.Read())
{
Level lev = new Level();
lev.ID = Convert.ToInt32(reader.GetValue(0));
lev.Name = reader.GetValue(1).ToString();
lev.levelScore = Convert.ToInt32(reader.GetValue(2));
lst.Add(lev);
}
}
selectCmd.Transaction.Connection.Close();
}
Constants.conn.Close();
levelList.ItemsSource = lst;
}
It sets the items on the page. I navigate on the detail page. The problem comes when I navigate back to the MainPage... Although the State is Clear and the levelItems is 0 It renders The previous view of the page and when it tries to access the sqlConnection throwsan exception.