public void LoadNotes() { if (IsBusy) return; IsBusy = true; bool shouldClose = false; // Is the database already open? if (conn.State != ConnectionState.Open) { shouldClose = true; conn.Open(); } // Execute query using (var command = conn.CreateCommand()) { // Create new command command.CommandText = "SELECT Id,Name,Observations from [tblNotes] ORDER by Id DESC"; try { //await DataStore.GetItemsAsync(true); using (var reader = command.ExecuteReader()) { while (reader.Read()) { MMNote item = new MMNote(); // Pull values back into class item.Id = Convert.ToString(reader[0]); item.Name = Convert.ToString(reader[1]); item.Observations = Convert.ToString(reader[2]); NoteItems.Add(item); } } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } } // Should we close the connection to the database if (shouldClose) { conn.Close(); } }
public void ReloadNotes() { NoteItems.Clear(); LoadNotes(); }