Data Grid shows no data VB.NET

0

Hello good night I wanted to ask for help, I have a query to an excel file, which works the connection, but at the time of doing the SELECT * FROM , all the columns appear in the datagridview but the data does not appear ... I wanted to know if someone happened to him and how to solve it. Code step.

Public Sub prueba123()
    Dim nombretabla As String
    Using conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Programador\Desktop\Compartido\Datos_Precios_20180904.xlsx; Extended Properties=""Excel 12.0 Xml;HDR= YES"";")
        Try
            conn.Open()
            Using dt As DataTable = conn.GetSchema("Tables")
                Dim query As IEnumerable(Of String) =
                        From row As DataRow In dt.Rows.Cast(Of DataRow)()
                        Where CStr(row.Item("TABLE_TYPE")).ToUpperInvariant() = "TABLE"
                        Select CStr(row.Item("TABLE_NAME"))
                'Order By row.Item("TABLE_NAME")
                nombretabla = query.ToList(0)
            End Using

            Using cmd As New OleDb.OleDbDataAdapter("SELECT * from [" + nombretabla + "]", conn)
                Dim dta As New DataTable
                cmd.Fill(dta)
                'dta.Load(cmd.ExecuteReader)
                frmPreciosImportar.DataGridView1.DataSource = dta
            End Using
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Using
End Sub

I hope you can help me, thank you very much and good evening!

    
asked by Julian Sodo 06.09.2018 в 00:05
source

1 answer

0

Thank you very much for answering. my datagridview1 does not have predefined columns. I tried testing with the predefined datagridview and it did not work either ... The day is filled with columns but not Rows. In count 0. I do not understand why this happens.

This is my excel table.

As you can see, I have a lot of records, but in the Form only the columns appear ..

    
answered by 06.09.2018 в 19:21