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!