public Boolean DeleteFromDB() { String modelo, familias, competencias, praticas, perguntas; this.loadFull(this.owner, null); SqlConnection conn = new SqlConnection(DBHelper.ConnectionString); SqlCommand command = new SqlCommand(); command.Connection = conn; // apagar o modelo modelo = "delete modelo where id= " + this.modeloID.ToString(); familias = "delete familia where id in ( "; competencias = "delete competencia where id in ( "; praticas = "delete Pratica where id in ( "; perguntas = "delete Pergunta where id in ( "; foreach (FamiliaCompetencias fam in this.familias.Values) { familias += fam.FamiliaID.ToString() + ","; foreach (Competencia comp in fam.Competencias.Values) { competencias += fam.FamiliaID.ToString() + ","; foreach (Pratica prat in comp.Praticas.Values) { praticas += prat.PraticaID.ToString() + ","; foreach (Pergunta perg in prat.Perguntas.Values) { perguntas += perg.PerguntaID.ToString() + ","; } } } } competencias = competencias.Substring(0, competencias.Length - 1); competencias += ")"; familias = familias.Substring(0, familias.Length - 1); familias += ")"; praticas = praticas.Substring(0, praticas.Length - 1); praticas += ")"; perguntas = perguntas.Substring(0, perguntas.Length - 1); perguntas += ")"; command.CommandType = CommandType.Text; conn.Open(); try { command.CommandText = modelo; command.ExecuteNonQuery(); command.CommandText = familias; command.ExecuteNonQuery(); command.CommandText = competencias; command.ExecuteNonQuery(); command.CommandText = praticas; command.ExecuteNonQuery(); command.CommandText = perguntas; command.ExecuteNonQuery(); } catch { conn.Close(); return false; } conn.Close(); return true; }