Thryn
Thryn

Reputation: 455

DataGridView stay empty even if SQL request is right

So, I simply need to fill a DataGridView of a WinForm with the result of a SQL request that I tried in MySQL Workbench and works perfectly.

It's not the first time I'm doing this in this particular program and all the others worked fine. However, no matter what I do, the DataGridView stays empty.

Here goes my code :

Dim BindingName As New BindingSource, ProdSet As New DataTable

    Private Sub SelectAllFacture()

        ClassConfig.Connexion.Open()

        ProdSet.Clear()

        Dim Requete As String
        Requete = "SELECT * FROM Product"

        Try
            Dim Cmd As New MySqlCommand
            With Cmd
                .Connection = ClassConfig.Connexion
                .CommandText = Requete
            End With

            Dim Adpt As New MySqlDataAdapter(Cmd)
            Adpt.Fill(ProdSet)
        Catch ex As Exception
            Autorisations.ErrorCheck(ex)
        End Try

        ClassConfig.Connexion.Close()

        BindingName.DataSource = ProdSet
        DataGridView.DataSource = BindingName

    End Sub

To explicit what is not shown :

Upvotes: 0

Views: 44

Answers (1)

Jon Roberts
Jon Roberts

Reputation: 2282

Instead of Filling a Dataset (prodset), make it a datatable

Dim prdtable as new DataTable

then

Adpt.Fill(prdtable)
BindingName.DataSource = prdtable

Also make sure you have either already added the correct columns to the DataGridView or set:

dataGridView.AutoGenerateColumns = true

Upvotes: 2

Related Questions