This works:
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dtSchema As DataTable
Dim drSchema As DataRow
Dim strForTextBox As String
Dim strTableName As String
Dim strSelect As String = "SELECT * FROM [{0}]"
Dim da As New OleDbDataAdapter
Dim ds As New DataTable
Dim fDlg As New OpenFileDialog
fDlg.Filter = "Excel Spreadsheets (*.xls)|*.xls"
fDlg.ShowDialog()
If fDlg.FileName.Length > 0 Then
Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & fDlg.FileName & _
";Extended Properties=Excel 8.0;")
cn.Open()
dtSchema = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
'DataGrid1.SetDataBinding(dtSchema, "")
drSchema = dtSchema.Rows(0)
strTableName = drSchema("TABLE_NAME")
Dim cmd As New OleDbCommand(String.Format(strSelect, strTableName))
cmd.Connection = cn
da.SelectCommand = cmd
da.Fill(ds)
'For Each drSchema In dtSchema.Rows
' strForTextBox = strForTextBox & "Table name = " & drSchema("TABLE_NAME") & vbCrLf
'Next
DataGrid1.DataSource = ds
'TextBox1.Text = strForTextBox
cn.Close()
cn.Dispose()
End If
End Sub
I just love a challenge