Getting sheet names from an excel spreadsheet

nismo

Member
Joined
Jun 30, 2006
Messages
18
Programming Experience
3-5
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim DS As DataSet

MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; data source=" & txtFile.Text & "; Extended Properties=Excel 8.0;")
MyCommand =
New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
DS =
New System.Data.DataSet
MyCommand.Fill(DS)
MyConnection.Close()


My problem with this code is that the sheet name wont always been Sheet1. Is there any way i can have a query that will just select the first spreadsheet without me having to know the name of it? Is there a way to refer to tables by index rather than name?
 
Back
Top