Write data from two Datagridview to the Sql Server database

Asked

Viewed 28 times

0

I’m not able to record the data that are in two dataGridView, the data that are in the two Datagridview are in a single Class, I have a code ready but would serve only for a Datagrid, in the same for wanted to put another Grid if possible, or if there were any other way to do it, I would appreciate the help.

 public void InserirItensOs()
    {
        try
        {
            if (DtGridServico.Rows.Count > 1)
            {
                for (int i = 0; i < DtGridServico.Rows.Count - 1; i++) //quero colocar outro GridViews no for.
                {
                    DetalheOrdemServico ordem = new DetalheOrdemServico();
                    ordem.OrdemServicoId = Convert.ToInt32(DtGridServico.Rows[i].Cells[0].Value);
                    ordem.NomeServico = DtGridServico.Rows[i].Cells[1].Value.ToString();
                    ordem.NomeMecanico = DtGridServico.Rows[i].Cells[2].Value.ToString();
                    ordem.VlrServDetalhe = Convert.ToDecimal(DtGridServico.Rows[i].Cells[3].Value);
                    ordem.ServicoId = Convert.ToInt32(DtGridServico.Rows[i].Cells[4].Value);

                    context.detalheOrdemServicos.Add(ordem);
                }
            }
  • You will have to use or go to "read" the other datagrid.

  • GOOD MORNING FRIEND THANK YOU FOR THE FORCE, I PUT ANOTHER FOR THE OTHER DATAGRIDVIEW, BUT IN TIME TO SAVE GIVE PRODUCT IP CONFLICT, WHAT AM I DOING AND A SERVICE ORDER SCREEN, WHERE A GRID I PUT THE SERVICES, AND THE OTHER GRID I PUT THE PRODUCTS AND THEN WANT TO SAVE THE TWO GRID IN A TABLE IN SQL SERVER.

  • friend I managed to record the data of the two Datagridview thanks for the force.

No answers

Browser other questions tagged

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