troubleshooting Question

Import Excel Data Using Generic Sheet Name

Avatar of JS List
JS ListFlag for United States of America asked on
Web Applications
5 Comments1 Solution293 ViewsLast Modified:
Hello,
I'm importing data from an excel spreadsheet into an ASP.NET web page.  The problem is the sheet name keeps changing.  It's always the first sheet in the excel book - but the users change the name.

Is there a generic name for the first sheet in Excel.   So if the user names the sheet to "employees" - when I make a connection can I use something like [Sheet(0)]?

Using ASP.NET 4.0 and xlsx file.

Here's my typical connection:  (Source name not complete path here.)
In Web.config
 <add name="csXLMembers" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=...\Members.xlsx;Extended Properties=Excel 12.0"/>

Code Behind aspx Page
 Dim conString As String = ConfigurationManager.ConnectionStrings("csXLMembers").ConnectionString

****  The following line is where I want to use a generic name instead of Sheet1$
 Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [Sheet1$]", con)

JS
ASKER CERTIFIED SOLUTION
JS List

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros