public void LoadAankopen(SqliteConnection conn, string id) { bool shouldClose = false; // clear last connection to preventcirculair call to update _conn = null; // Is the database already open? if (conn.State != ConnectionState.Open) { shouldClose = true; conn.Open(); } using (var commandAK = conn.CreateCommand()) { try { // Create new command commandAK.CommandText = "SELECT DISTINCT ID FROM [Aankoop] WHERE PersoonID = '" + ID + "'"; using (var readerAK = commandAK.ExecuteReader()) { while (readerAK.Read()) { var aankoop = new AankoopModel(); var idAK = (string)readerAK["ID"]; aankoop.Load(conn, idAK); Aankopen.Add(aankoop); } } } catch (Exception Exception) { Debug.WriteLine(Exception.Message); } } if (shouldClose) { conn.Close(); } // Save last connection _conn = conn; }
void LoadAankopen(SqliteConnection conn, string PersoonID) { bool shouldClose = false; // Is the database already open? if (conn.State != ConnectionState.Open) { shouldClose = true; conn.Open(); } // Execute query using (var command = conn.CreateCommand()) { try { // Create new command command.CommandText = "SELECT DISTINCT ID FROM [Aankoop] WHERE PersoonID = '" + PersoonID + "'"; using (var reader = command.ExecuteReader()) { while (reader.Read()) { var aankoop = new AankoopModel(); var id = (string)reader["ID"]; aankoop.Load(conn, id); Aankopen.Add(aankoop); } } } catch (Exception Exception) { Debug.WriteLine(Exception.Message); } } if (shouldClose) { conn.Close(); } }