How can I remove some columns from a table in c # that I bring from Mysql?

0

I want to show only some of the fields that I bring from my query, but when viewing them, they all appear in the grid

List<Pojos.agregarProducto> lstProd = new List<Pojos.agregarProducto>();
        MySqlDataReader dr;

        MySqlCommand cm = new MySqlCommand("select nombres,cantidad,precio,total" +
            " from venta_Producto where idVenta =" + id, cn.Conectar());
        dr = cm.ExecuteReader();
        while (dr.Read())
        {
            Pojos.agregarProducto objAp = new Pojos.agregarProducto();
            objAp.Nombres = dr.GetString("nombres");
            objAp.Cantidad = dr.GetDouble("cantidad");
            objAp.Precio = dr.GetDouble("precio");
            objAp.Total = dr.GetDouble("total");

            lstProd.Add(objAp);
        }
        cn.Cerrar();
        return lstProd;
    }
    
asked by pedro diaz peterlp15x 01.07.2018 в 19:46
source

1 answer

0

What you could do is the following:

 return lstProd.Select(model => new { model.nombres,
                                      model.cantidad,
                                      model.precio,
                                      model.total
                                    });
    
answered by 01.07.2018 в 20:06