write data from a Datagridview to the database

Asked

Viewed 19 times

0

Good morning, I am making an application similar to a sale, which contains sales and sales items. my problem is that I am not able to save the items of sale that is in datagridView, I am using Entity framework, it is only saving a record.

public void InserirItens()
        {
            ItensToras itens1 = new ItensToras();
           
            try
            {
                if (dtGridItens.Rows.Count > 1)
                {
                    for (int i = 0; i < dtGridItens.Rows.Count -1; i++)
                    {
                        itens1.IdCargas = Convert.ToInt32(dtGridItens.Rows[i].Cells[0].Value);
                        itens1.IdAlce = Convert.ToInt32(dtGridItens.Rows[i].Cells[1].Value);

                        context.itensToras.Add(itens1);
                    }
                   
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

inserir a descrição da imagem aqui

  • should instantiate a new object for each time it will insert a new one, ie within the for include this ItensToras itens1 = new ItensToras();

  • Friend God bless you, I got thank God thank you very much from my heart.

No answers

Browser other questions tagged

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