problem GridView

0

LíneaFactura

  • idLineFactura
  • amount
  • ProductID

product

  • ProductID
  • name
  • reference
  • unit price
  • idCategory

    SELECT  L.cantidad, P.nombre , P.precioUnitario, (L.cantidad * 
    P.precioUnitario) as precioSubTotal FROM lineaFacturaTMP L , producto P 
    WHERE p.idProducto = L.idProducto
    

The problem I have is that I am trying to list cantidad , nombre del producto , precio , subtotal  in a gridView , although I put precioSubTotal in the dataField I get an error:

  

{"No field or property 'priceSubTotal' was found in the   selected data source. "},

I execute the query in the sqlManagementStudio and if it brings me the data, but the gridView throws me the error

    
asked by Jhonatan Valencia 15.04.2017 в 01:01
source

1 answer

0

GridView

<asp:GridView ID="gvLineaFactura" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" DataKeyNames="idLineaFactura" OnRowDeleting="gvLineaFactura_RowDeleting">
            <Columns>
                <asp:BoundField DataField="idLineaFactura" HeaderText="ID" />
                <asp:BoundField DataField="cantidad" HeaderText="Cantidad" />
                <asp:BoundField HeaderText="Descripcion" DataField="nombre" />
                <asp:BoundField DataField="precioUnitario" HeaderText="Valor Unitario" />
                <asp:BoundField DataField="precioSubTotal" HeaderText="sub Total" />
                <asp:CommandField ShowDeleteButton="True" />
            </Columns>
            <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
            <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
            <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#F7F7F7" />
            <SortedAscendingHeaderStyle BackColor="#4B4B4B" />
            <SortedDescendingCellStyle BackColor="#E5E5E5" />
            <SortedDescendingHeaderStyle BackColor="#242121" />
        </asp:GridView>


capa  de presentacion presentacion

BusisnessVenta negocio = new BusisnessVenta();

gvLineaFactura.DataSource = negocio.listarLineafactura();
gvLineaFactura.DataBind(); 

capa negocio

 public List<LineaFacturaTMP> listarLineafactura()
        {
            return linea.listarLineafactura();
        }

capa datos


 public List<LineaFacturaTMP> listarLineafactura()
        {
            List<LineaFacturaTMP> lista = new List<LineaFacturaTMP>();


            try
            {
                using (SqlConnection con = new SqlConnection())
                {
                    con.ConnectionString = this.datosConexion;
                    con.Open();

                    string query = "SELECT L.idLineaFactura,  L.cantidad, P.nombre , P.precioUnitario, (L.cantidad * P.precioUnitario) as precioSubTotal   FROM lineaFacturaTMP L , producto P WHERE p.idProducto = L.idProducto";

                    SqlCommand cmd = new SqlCommand(query, con);
                    SqlDataReader lector = cmd.ExecuteReader();

                    while (lector.Read())
                    {
                        LineaFacturaTMP lineaFacturaTMP = new LineaFacturaTMP()
                        {
                            idLineaFactura =  Convert.ToInt32(lector["idLineaFactura"]),
                            Cantidad = Convert.ToInt32(lector["cantidad"]),
                            nombre = Convert.ToString(lector["nombre"]),
                            PrecioUnitario = Convert.ToDecimal(lector["precioSubTotal"]),
                            SubTotal = Convert.ToDecimal(lector["precioSubTotal"])
                        };
                        lista.Add(lineaFacturaTMP);
                    }

                }
            }
            catch (Exception e)
            {

                throw e;
            }

            return lista;

        }
    
answered by 15.04.2017 в 03:21