public static List <TipoDocumentoItemVM> obtenerListaTipoDocumento() { List <TipoDocumentoItemVM> resultado = new List <TipoDocumentoItemVM>(); string cadenaConexion = System.Configuration.ConfigurationManager.AppSettings["cadenaBD"].ToString(); SqlConnection cn = new SqlConnection(@"Data Source=JGA_NOTEBOOK;Initial Catalog=master;Integrated Security=True"); try { SqlCommand cmd = new SqlCommand(); string consulta = "SELECT * FROM TiposDocumentos"; cmd.Parameters.Clear(); cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = consulta; cn.Open(); cmd.Connection = cn; SqlDataReader dr = cmd.ExecuteReader(); if (dr != null) { while (dr.Read()) { TipoDocumentoItemVM aux = new TipoDocumentoItemVM(); aux.Id = int.Parse(dr["Id"].ToString()); aux.Nombre = dr["Nombre"].ToString(); resultado.Add(aux); } } } catch (Exception) { throw; } finally { cn.Close(); } return(resultado); }
public static List <TipoDocumentoItemVM> obtenerListaTipoDocumento() { List <TipoDocumentoItemVM> resultado = new List <TipoDocumentoItemVM>(); SqlConnection cn = new SqlConnection(cadenaConexion); try { SqlCommand cmd = new SqlCommand(); string consulta = "SELECT * FROM TiposDocumentos"; cmd.Parameters.Clear(); cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = consulta; cn.Open(); cmd.Connection = cn; SqlDataReader dr = cmd.ExecuteReader(); if (dr != null) { while (dr.Read()) { TipoDocumentoItemVM aux = new TipoDocumentoItemVM(); aux.Id = int.Parse(dr["Id"].ToString()); aux.Nombre = dr["Nombre"].ToString(); resultado.Add(aux); } } } catch (Exception) { throw; } finally { cn.Close(); } return(resultado); }