Is there a way to add sql data depending on the GridView row? ASPX and C # with Visual Studio

0

My idea is to show in a GridView information that I have of tables in my database, as I need to show two Codes of a product, I have to call two SELECT, one for each code. I want the end user to visualize a summary of some sales, in the following way:

That's in a GridView I use a SELECT to display Code 1 and OTHER Select data for Code 2. My question is whether I can add only one SELECT for the Alternate rows, and others for the others. This method shows me Code1 but I need to call another SELECT to see Code2

  private void MostrarGird()
{
    DataTable dttr = new DataTable();
    OdbcCommand cmdd = new OdbcCommand("SELECT SlpCode FROM Vendedores WHERE SlpName = ?", cn);
    cmdd.Parameters.AddWithValue("nombre", ListBox1.SelectedValue);
    OdbcDataAdapter dda = new OdbcDataAdapter(cmdd);
    dda.Fill(dttr);
    if (dttr.Rows.Count == 1)
    {
        DataTable dta = new DataTable();
        DataRow fila = dttr.Rows[0];
        OdbcCommand cmda = new OdbcCommand("SELECT T0.ItemCode as Codigo, sum(Convert(int,A.VPiezas)) as Cantidad, sum(Convert(money, (A.VImporte)))/sum(Convert(money,(A.VPiezas))) as PrecioU FROM Articulos T0 INNER JOIN Codigos T1 ON T0.[ItemCode] = T1.[Code] INNER JOIN Code T2 ON T1.[Code] = T2.[Father] INNER JOIN Articulos T3 ON T2.[Code] = T3.[ItemCode] INNER JOIN SVenta A ON A.Codigo1 = T0.ItemCode WHERE T0.TreeType = 'T' and T3.ItmsGrpCod in (110, 119) and A.SlpCode = ? and A.Fecha = ? group by T0.ItemCode union SELECT T0.ItemCode as Codigo, sum(Convert(int,A.VKilos)) as Cantidad, sum(Convert(money, (A.VImporte)))/sum(Convert(money,(A.VKilos))) as PrecioU FROM Articulos T0 INNER JOIN Codigos T1 ON T0.[ItemCode] = T1.[Code] INNER JOIN Code T2 ON T1.[Code] = T2.[Father] INNER JOIN Articulos T3 ON T2.[Code] = T3.[ItemCode] INNER JOIN SVenta A ON A.Codigo2 = T0.ItemCode WHERE T0.TreeType = 'T' and T3.ItmsGrpCod in (111) and A.SlpCode = ? and A.Fecha = ? group by T0.ItemCode", cn);
        cmda.Parameters.AddWithValue("codigo", Convert.ToString(fila["SlpCode"]));
        cmda.Parameters.AddWithValue("fecha", DateTime.Parse(Fecha.Text));
        cmda.Parameters.AddWithValue("codig", Convert.ToString(fila["SlpCode"]));
        cmda.Parameters.AddWithValue("feca", DateTime.Parse(Fecha.Text));
        OdbcDataAdapter daa = new OdbcDataAdapter(cmda);
        daa.Fill(dta);
        GRILLA.DataSource = dta;
        GRILLA.DataBind();
    }
    cn.Close();
}
    
asked by Elizabeth 22.06.2018 в 18:59
source

0 answers