public static List <Estudio> GetAll() { DBConnect db = new DBConnect(); try { List <Estudio> estudios = new List <Estudio>(); string query = "SELECT * FROM Estudios;"; //Open connection db.OpenConnection(); //Create Command MySqlCommand cmd = new MySqlCommand(query, db.connection); //Create a data reader and Execute the command MySqlDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { var estudio = new Estudio(); estudio.cod_estudio = Convert.ToInt32(dataReader["cod_estudio"]); estudio.desc_estudio = Convert.ToString(dataReader["desc_estudio"]); estudios.Add(estudio); } dataReader.Close(); db.CloseConnection(); return(estudios); } catch (Exception ex) { db.CloseConnection(); throw new Exception(ex.Message); } finally { if (db.OpenConnection() == true) { db.CloseConnection(); } ; } }
public static List<Estudio> GetAll() { DBConnect db = new DBConnect(); try { List<Estudio> estudios = new List<Estudio>(); string query = "SELECT * FROM Estudios;"; //Open connection db.OpenConnection(); //Create Command MySqlCommand cmd = new MySqlCommand(query, db.connection); //Create a data reader and Execute the command MySqlDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { var estudio = new Estudio(); estudio.cod_estudio = Convert.ToInt32(dataReader["cod_estudio"]); estudio.desc_estudio = Convert.ToString(dataReader["desc_estudio"]); estudios.Add(estudio); } dataReader.Close(); db.CloseConnection(); return estudios; } catch (Exception ex) { db.CloseConnection(); throw new Exception(ex.Message); } finally { if (db.OpenConnection() == true) { db.CloseConnection(); }; } }