Foreach or for by invoice item

Asked

Viewed 70 times

0

I need to do one foreach per item in my code only I’m not able to accomplish.

Ex.: I have a note that has 2 items, and I need to read the information of the note per item, I read item 01 and then I read item 02, only I’m not able to implement it in my code below.

Follows 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();
}
  • And what is the difficulty, young man?

  • And what’s the problem? What did you try to do with foreach?

  • then I need to do a foreach to read per item of invoice and I am not able to do this foreach, I need to read item 01 product x and fill the textbox that step inside the reportview that is in the code, ai then read p item 02 product y and pass the information to the textbox in the reportviwer below . I don’t know if I can explain my need.

  • If you notice in my query above I manually fill in the note number and item number below I read and fill in the textbox inside the datareader, there I pass all the parameters filled into the textbox in reportviwer.

1 answer

0


Remove the key from the query item, and loop the DataReader. The Processing you need to do on the line, do 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();
  • Thanks Rovann, but what I’m filling in the textbox, I’m throwing into the reportview below in the code.

  • I don’t think it’s necessary to play for the textbox... play straight for the reportview

  • Rovann thanks for the help, but still missing some detail, because and the following, in the note I’m typing has two items, 01 and 02, when I run the code, he reads the information of dosi items but on the reportviwer screen only shows on the screen item 02, does not show item 01, had to show item 01 one page and item 02 other page.

  • I believe that there is something with the reportviewer, in which case, I don’t work with it and I wouldn’t know how to help you. As the question only talks about the loop in the items, I believe it can be finalized.

  • 1

    Thank you very much, Rovann....

Browser other questions tagged

You are not signed in. Login or sign up in order to post.