Foreach or for invoice item [closed]

0

I need to make a foreach per item in my code, but I can not do it.

Eg: I have a note that has 2 items, and I need to read the information of the note by item, I read item 01 and then I read item 02, but I am not able to implement this in my code below. >

Follow my code.

private void btn_laudo_Click(object sender, EventArgs e)
{
    string ItemNota = @"SELECT 
                    SD.D2_COD, 
                    SD.D2_LOTECTL, 
                    QR.QER_REVI, 
                    SD.D2_ITEM 
                  FROM SD2020 AS SD 
                  INNER JOIN QER020 AS QR WITH(NOLOCK) ON QR.QER_LOTE = SD.D2_LOTECTL 
                  WHERE SD.D2_DOC = '" + txt_nota.Text + "' AND SD.D2_ITEM = '" + txt_item.Text + "'";

    SqlCommand comando = new SqlCommand(ItemNota, conex);
    conex.Open();
    SqlDataReader ler = comando.ExecuteReader();
    if (ler.Read() == true)
    {
        txt_lote.Text = ler[1].ToString();
        txt_codprod.Text = ler[0].ToString();
        txt_revi.Text = ler[2].ToString();
    }
    conex.Close();

    this.CabeçalhoLaudoTableAdapter.Fill_CabLaudo(this.DSLaudosPS.CabeçalhoLaudo, txt_nota.Text, txt_item.Text);
    this.CorpoLaudoTableAdapter.Fill_CorpoLaudo(this.DSLaudosPS.CorpoLaudo, txt_codprod.Text, txt_lote.Text, txt_revi.Text);
    this.rpw_laudo.RefreshReport();
}
    
asked by anonymous 04.09.2017 / 15:18

1 answer

0

Remove the query item key, and loop in the DataReader . The Processing you need to do on the line, do it inside the loop.

string ItemNota = @"SELECT 
                    SD.D2_COD, 
                    SD.D2_LOTECTL, 
                    QR.QER_REVI, 
                    SD.D2_ITEM 
                  FROM SD2020 AS SD 
                  INNER JOIN QER020 AS QR WITH(NOLOCK) ON QR.QER_LOTE = SD.D2_LOTECTL 
                  WHERE SD.D2_DOC = '" + txt_nota.Text + "';";

    SqlCommand comando = new SqlCommand(ItemNota, conex);
    conex.Open();
    SqlDataReader ler = comando.ExecuteReader();

    while (ler.Read())
    {
          //faça o que precisa com cada linha aqui
        this.CabeçalhoLaudoTableAdapter.Fill_CabLaudo(this.DSLaudosPS.CabeçalhoLaudo, txt_nota.Text, txt_item.Text);
        this.CorpoLaudoTableAdapter.Fill_CorpoLaudo(this.DSLaudosPS.CorpoLaudo, ler[0].ToString(),ler[1].ToString(), ler[2].ToString());
        this.rpw_laudo.RefreshReport();
    }
    ler.Close();
    conex.Close();
    
04.09.2017 / 15:42