/// <summary> /// lista de persona /// </summary> /// <returns></returns> public List <clsPersona> getListadoPersonasDAL() { clsPersona oPersona; List <clsPersona> lista = new List <clsPersona>(); clsMyConnection miConexion = new clsMyConnection(); SqlCommand miComando = new SqlCommand(); SqlDataReader miLector; try { miConexion.getConnection(); miComando.CommandText = "Select IDPersona,nombre,apellidos,fechaNac," + "direccion,telefono From personas"; miComando.Connection = miConexion.connection; miLector = miComando.ExecuteReader(); if (miLector.HasRows) { while (miLector.Read()) { oPersona = new clsPersona(); oPersona.id = (int)miLector["IDPersona"]; oPersona.Nombre = (string)miLector["nombre"]; oPersona.Apellidos = (string)miLector["apellidos"]; oPersona.FechaNac = (DateTime)miLector["fechaNac"]; oPersona.Direccion = (string)miLector["direccion"]; oPersona.Telefono = (string)miLector["telefono"]; lista.Add(oPersona); } //Fin while //miLector.Close(); } //Fin if } catch (Exception) { throw; } finally { miConexion.closeConnection(); } return(lista); }
public List <clsPersona> getListadoPersonasDAL() { List <clsPersona> listadoPersonas; clsMyConnection miConexion; listadoPersonas = new List <clsPersona>(); miConexion = new clsMyConnection(); SqlConnection conexion = new SqlConnection(); SqlCommand command = new SqlCommand(); SqlDataReader lector; clsPersona oPersona; try { conexion = miConexion.getConnection(); command.CommandText = "SELECT * FROM personas"; command.Connection = conexion; lector = command.ExecuteReader(); if (lector.HasRows) { while (lector.Read()) { oPersona = new clsPersona(); oPersona.id = (int)lector["IDPersona"]; oPersona.nombre = (string)lector["nombre"]; oPersona.apellidos = (string)lector["apellidos"]; oPersona.fechaNac = (DateTime)lector["fechaNac"]; oPersona.direccion = (string)lector["direccion"]; oPersona.telefono = (string)lector["telefono"]; listadoPersonas.Add(oPersona); } } } catch (Exception e) { throw e; } return(listadoPersonas); }