Urgent!!!Finding Excel sheet names dynamically in VB.NET?

The following code works fine if excel default sheet 1 name is "Sheet1".
My question is If user changes this sheet 1 name to "ABC" and uploaded.
how the following code works? it goes to error handling. Please can you let me know how to track sheet names or how retreive data for this condition dynamically.

Waiting for reply. Thanks in advance.
Ram

Public GetDataFromExcel() as DataSet
Dim sSheet as string = "Sheet1"
Dim myDataset As New DataSet()
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("/excelreading/") & "excel/" & strFileNameOnly & ";" & _
"Extended Properties=Excel 8.0;"
Dim myData As New OleDbDataAdapter("SELECT * FROM [" & sSheet & "$]", strConn)
myData.Fill(myDataset)
Return myDataset
End Sub

[884 byte] By [RamuDevarasetty] at [2007-12-16]
# 1
Hi,
If you want to traverse to the sheets of an excel file, then you'll have to use the Excel API or PIA. Here's some references to look at...

Programming Word and Excel Applications
Accessing Data Sample
Automating Excel Using the Excel Object Model

cheers,
Paul June A. Domag

PaulDomag at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2
Hi Ramu,

I think there is a slightly easier way to get at the work sheet information dynamically (or metadata).

To do this you need to call GetOleDbSchemaTable method with the Microsoft OLE DB Managed Provider and the Microsoft OLE DB Provider for Jet.

Worksheets will be treated as System Tables, and ranges will be treated as tables.

There is a full article with source code here:
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q318373

Hope this helps.

Best,
Paul Yuknewicz
Visual Basic Team

PaulYuk_MS at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...