Error: Value can not be null. Parameter name: dataTable. VB.NET

2

I'm trying to make a query in the database and display it in a datagrid , I do not have as much experience, I do technical course and it's my first question here, the code I'm using is this:

Public Sub PreencheDataGrid(ByRef x As DataGridView, ByVal op1 As Integer, ByVal op2 As Integer)
    Dim SDA As New MySqlDataAdapter
    Dim bSource As New BindingSource

    conectaBanco()

    Dim query As String

    query = "SELECT * FROM vw_tb_clientes"

    objcmd = New MySqlCommand(query, con)
    SDA.SelectCommand = objcmd
    SDA.Fill(dbDataSet)
    bSource.DataSource = dbDataSet

    'Deixa o DataGridView limpo
    x.DataSource = Nothing

    x.DataSource = bSource
    SDA.Update(dbDataSet)

    fechaBanco()
End Sub

As I understand with my debug , the error is in the code SDA.Fill(dbDataSet) , but I do not know what is happening since I have another datagridview with almost the same code and functional, someone could you help me?

    
asked by anonymous 24.05.2017 / 15:33

1 answer

2

Failed to specify table in its DataSet . See the implementations below to fix the problem:

Public Sub PreencheDataGrid(ByRef x As DataGridView, ByVal op1 As Integer, ByVal op2 As Integer)
    Dim SDA As New MySqlDataAdapter
    Dim bSource As New BindingSource

    conectaBanco()

    Dim query As String

    query = "SELECT * FROM vw_tb_clientes"

    objcmd = New MySqlCommand(query, con)
    SDA.SelectCommand = objcmd

    'Declarei aqui para mostrar o uso do parâmetro
    Dim dbDataSetAs New DataSet("Tab") 'Tab será o nome do nosso dataset e da nossa tabela
    '---
    SDA.Fill(dbDataSet, "Tab") 'Preenche os dados na Tab
    bSource.DataSource = dbDataSet
    bSource.DataMember = "Tab" 'Indica que é para puxar da Tab os dados

    'Deixa o DataGridView limpo
    x.DataSource = Nothing

    x.DataSource = bSource
    SDA.Update(dbDataSet, "Tab")

    fechaBanco()
End Sub
    
24.05.2017 / 16:27