Datagridview does not store information in the table

0

I have a datagridview that is fed by a search in a database to hold a sale but I can only sell one product at a time because the sales chart can not receive 2 or more products simultaneously already tried to separate the sales table into 2: sales_and sales, where sales stores the sales code, the form of payment and the date, while items_store stores the products. When I finish the sale, only the storage in the sales table (which is done by a procedure) and in the itens_venda nothing happens (the storage here is performed by the table adapter and data table) if you guys could help me I would be very grateful

follow the end of purchase button code

private void btnFinCompra_Click(object sender, EventArgs e)
    {
        try
        {
            int codigo = Convert.ToInt16(TAVendas.insereVenda(DateTime.Now, pagamento));
            txtCodVenda.Text = codigo.ToString();
            try
            {
                for(int cont = 0; cont<=dgvVenda.Rows.Count - 2; cont++)
                {

                    DadosDataSet.tbitensvendaRow linha;
                    linha = (DadosDataSet.tbitensvendaRow)DTitens.NewRow();
                    linha.BeginEdit();
                    linha.codvenda = Convert.ToInt16(txtCodVenda.Text);
                    linha.codproduto = Convert.ToInt16(dgvVenda.Rows[cont].Cells["clmCodigo"].Value);
                    linha.nomecor = dgvVenda.Rows[cont].Cells["clmNomeCor"].Value.ToString();
                    linha.categoria = dgvVenda.Rows[cont].Cells["clmCategoria"].Value.ToString();
                    linha.subcategoria = dgvVenda.Rows[cont].Cells["clmSubCat"].Value.ToString();
                    linha.subcategoria2 = dgvVenda.Rows[cont].Cells["clmSubCat2"].Value.ToString();
                    linha.qtde = Convert.ToInt16(dgvVenda.Rows[cont].Cells["clmQtde"].Value);
                    linha.peso = Convert.ToDouble(dgvVenda.Rows[cont].Cells["clmPeso"].Value);
                    linha.marcatipo = dgvVenda.Rows[cont].Cells["clmMarcaTipo"].Value.ToString();
                    linha.precovenda = Convert.ToDouble(dgvVenda.Rows[cont].Cells["clmPreco"].Value);
                    linha.totalvenda = Convert.ToDouble(dgvVenda.Rows[cont].Cells["clmSubTotal"].Value);
                    linha.EndEdit();
                    DTitens.Rows.Add(linha);

                }
                TAitens.Update(DTitens);
                MessageBox.Show("Venda realizada com sucesso", "Vendas", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro ao finalizar compra\n" + ex.Message, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                TAVendas.excluirVenda(Convert.ToInt16(txtCodVenda.Text));
            }
        }
        catch(Exception ex)
        {
            MessageBox.Show("Erro ao finalizar compra\n" + ex.Message, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
    
asked by anonymous 20.01.2018 / 01:21

0 answers