none
DataSet Referência de objeto não definida para uma instância de um objeto RRS feed

  • Question

  • Estou tentando carregar uma tabela de vendas, mas aparece uma mensagem sempre que o formulário carrega

    Private Sub nova_venda_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'DSFluxDataSet.tbPagamentos' table. You can move, or remove it, as needed.
            Me.TbPagamentosTableAdapter1.Fill(Me.DSFluxDataSet.tbPagamentos)
            'TODO: This line of code loads data into the 'DSFluxDataSet.tbColaboradores' table. You can move, or remove it, as needed.
            Me.TbColaboradoresTableAdapter2.Fill(Me.DSFluxDataSet.tbColaboradores)
            'TODO: This line of code loads data into the 'DSFluxDataSet.tbClientes' table. You can move, or remove it, as needed.
            Me.TbClientesTableAdapter2.Fill(Me.DSFluxDataSet.tbClientes)
            If Me.Text = "Nova venda" Then
                LimparCampos()
            ElseIf Me.Text = "Editar venda" Then
                With vendas.dgvVend.SelectedRows(0)
                    txtDt.Value = .Cells(2).Value
                    txtCliente.SelectedValue = .Cells(4).Value
                    txtResp.Text = .Cells(3).Value
                    txtPesq.Text = ""
                    IDSelecionado = .Cells(1).Value
                End With
                Dim prodid As Integer = vendas.dgvVend.SelectedRows(0).Cells(5).Value
                Dim qtd As Integer = vendas.dgvVend.SelectedRows(0).Cells(7).Value
                If dgvProds.Rows.Count > 0 Then dgvProds.Rows.Clear()
                Try
                    dgvProds.Rows.Add(prodid, DSFluxDataSet.tbVendas.FindBycolId(prodid).colResp, _
                                    DSFluxDataSet.tbProdutos.FindBycolId(prodid).colPrVnd, _
                                    qtd, DSFluxDataSet.tbProdutos.FindBycolId(prodid).colPrVnd * qtd)
                Catch ex As Exception
                    If My.Settings.debugmode = True Then
                        MsgBox(ex.Message, MsgBoxStyle.Critical, "Erro interno [DEBUG MODE]")
                    End If
                End Try
                txtDscPrc.Text = 0.ToString("0.00")
                txtDscDin.Text = 0.ToString("0.00")
                txtTt.Text = SomarColuna().ToString("0.00")
            End If
        End Sub

    A mensagem de erro aponta para essa linha:

    dgvProds.Rows.Add(prodid, DSFluxDataSet.tbVendas.FindBycolId(prodid).colResp, _
                                    DSFluxDataSet.tbProdutos.FindBycolId(prodid).colPrVnd, _
                                    qtd, DSFluxDataSet.tbProdutos.FindBycolId(prodid).colPrVnd * qtd)

    Alguém sabe o que tá acontecendo? Eu uso um SQL Server e todas as outras tabelas estão funcionando. Já reconectei o banco de dados inúmeras vezes.

    Saturday, July 7, 2018 2:35 PM

All replies

  • Please take note that this is an English language forum!

    As for your error message "DataSet Object reference not set to an instance of an object", maybe you should check if one of your DataTable objects (dgvProds, tbVendas or tbProdutos) returns null before using it.

    wizend

    Saturday, July 7, 2018 6:09 PM
  • English? 
    Saturday, July 7, 2018 7:26 PM
  • Hi MingaYaelCarvs,

    This forum is an English forum, it will be beneficial to resolve the issue if you post the thread in English. For your question, I would suggest that you could debug your application and set a break point on the following, check if the object named DSFluxDataSet and the tables in this Dataset is null.

    dgvProds.Rows.Add(prodid, DSFluxDataSet.tbVendas.FindBycolId(prodid).colResp, _
                                    DSFluxDataSet.tbProdutos.FindBycolId(prodid).colPrVnd, _
                                    qtd, DSFluxDataSet.tbProdutos.FindBycolId(prodid).colPrVnd * qtd)

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 9, 2018 3:25 AM
    Moderator