public List <Marca> Listar() { List <Marca> Marcas = new List <Marca>(); SqlDataReader Lector; SqlCommand Comando = new SqlCommand(); SqlConnection Conexion = new SqlConnection(); Marca Aux; try { Conexion.ConnectionString = "data source=NBBASAR605\\SQLEXPRESS; initial catalog=Negocio; integrated security=sspi"; Comando.CommandType = System.Data.CommandType.Text; Comando.CommandText = "select ID, Descripcion from [Negocio].[dbo].Marca"; Comando.Connection = Conexion; Conexion.Open(); Lector = Comando.ExecuteReader(); while (Lector.Read()) { Aux = new Marca((int)Lector["ID"], (string)Lector["Descripcion"]); Marcas.Add(Aux); } return(Marcas); } catch (Exception Ex) { throw Ex; } }
public List <Categoria> Lista() { SqlConnection conexion = new SqlConnection(); SqlCommand comando = new SqlCommand(); SqlDataReader Lector; List <Categoria> Lista = new List <Categoria>(); conexion.ConnectionString = "data source=.\\SQLEXPRESS; initial catalog = CATALOGO_DB; integrated security = sspi"; comando.CommandType = System.Data.CommandType.Text; comando.CommandText = "select Id,Descripcion from CATEGORIAS"; comando.Connection = conexion; conexion.Open(); Lector = comando.ExecuteReader(); while (Lector.Read()) { Categoria aux = new Categoria(); aux.ID = (int)Lector["Id"]; aux.Descripcion = (string)Lector["Descripcion"]; Lista.Add(aux); } Lector.Close(); conexion.Close(); return(Lista); }
public List <Articulos> Listar() { ///Declarar la shit necesaria para poder conectarse SqlConnection Conexion = new SqlConnection(); SqlCommand Comando = new SqlCommand(); SqlDataReader Lector; List <Articulos> lista = new List <Articulos>(); //Configurando conexion Conexion.ConnectionString = "data source = .\\SQLEXPRESS; initial catalog = CATALOGO_DB; integrated security = sspi"; Comando.CommandType = System.Data.CommandType.Text; Comando.CommandText = "select a.id as IdArt, a.Codigo, a.nombre, a.descripcion, a.imagenurl, a.precio, c.id as IdCategoria, c.Descripcion as Categoria,m.id as IdMarca, m.Descripcion as Marca from ARTICULOS as a join CATEGORIAS c on a.IdCategoria = c.id join MARCAS as m on m.Id = a.IdMarca"; //se ejecuta la conexion Comando.Connection = Conexion; try { Conexion.Open(); //se manda la query a seleccionar registros Lector = Comando.ExecuteReader(); //Logica una vez conectado, ¿qué tenemos que hacer? while (Lector.Read()) { Articulos Aux = new Articulos(); ///Tenemos que Instanciar un objeto auxiliar al que asignarle los valores ///leidos y de ahí sumarlo a la lista Aux.Id = (int)Lector["IdArt"]; Aux.Codigo = Lector.GetString(1); Aux.Nombre = Lector.GetString(2); Aux.Descripcion = Lector.GetString(3); Aux.Imagen = (string)Lector["ImagenUrl"]; Aux.Precio = Lector.GetSqlMoney(5); Aux.categoria = new Categoria(); Aux.categoria.Id = (int)Lector["IdCategoria"]; Aux.categoria.Descripcion = (string)Lector["Categoria"]; Aux.Marca = new Marca(); Aux.Marca.Descripcion = (string)Lector["marca"]; Aux.Marca.Id = (int)Lector["IdMarca"]; lista.Add(Aux); } Conexion.Close(); return(lista); } catch (Exception ex) { throw ex; } }
public List <Articulo> listar() { SqlConnection conexion = new SqlConnection(); SqlCommand comando = new SqlCommand(); SqlDataReader Lector; List <Articulo> Lista = new List <Articulo>(); conexion.ConnectionString = "data source=.\\SQLEXPRESS; initial catalog = CATALOGO_DB; integrated security = sspi"; comando.CommandType = System.Data.CommandType.Text; comando.CommandText = "Select A.Id,A.Codigo,A.Nombre,A.Descripcion,A.ImagenUrl,A.Precio,M.Descripcion Marca,M.Id IDMarca, C.Descripcion Categoria,C.Id IDCategoria " + "From ARTICULOS A, MARCAS M, CATEGORIAS C where A.IdMarca = M.Id and A.IdCategoria = C.Id"; comando.Connection = conexion; conexion.Open(); Lector = comando.ExecuteReader(); while (Lector.Read()) { Articulo aux = new Articulo(); aux.ID = (int)Lector["Id"]; aux.Codigo = (String)Lector["Codigo"]; aux.Nombre = (String)Lector["Nombre"]; aux.Descripcion = (String)Lector["Descripcion"]; aux.Precio = Convert.ToDouble(Lector["Precio"]); aux.ImagenUrl = (String)Lector["ImagenUrl"]; aux.Marca = new Marca(); aux.Marca.ID = (int)Lector["IDMarca"]; aux.Marca.Descripcion = (String)Lector["Marca"]; aux.Categoria = new Categoria(); aux.Categoria.ID = (int)Lector["IDCategoria"]; aux.Categoria.Descripcion = (String)Lector["Categoria"]; Lista.Add(aux); } Lector.Close(); conexion.Close(); return(Lista); }