Solved

ADO.Net - Excel - 1st Worksheet

Posted on 2009-06-29
3
377 Views
Last Modified: 2013-12-17
I use ADO.Net to open an Excel workbook.

If I know the name of the first worksheet, I can get the data no problem.

Is there a way to reference the first worksheet whatever its name is when creating the Command object?
0
Comment
Question by:Éric Moreau
3 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 400 total points
ID: 24735808
C# - Retrieve Excel Workbook Sheet Names.
http://www.codeproject.com/KB/aspnet/getsheetnames.aspx
0
 
LVL 15

Assisted Solution

by:mohan_sekar
mohan_sekar earned 100 total points
ID: 24735813
0
 
LVL 70

Author Comment

by:Éric Moreau
ID: 24735913
Excellent.

The answer is: cn.GetOleDbSchemaTable(OleDb.OleDbSchemaGuid.Tables, Nothing)
or: cn.GetSchema("Tables")

which both return a datatable.

The only problem with this is that you have no clue which sheet is the first one (as they seem to be sorted by name).

It is not really a problem for me as the workbook contains a single worksheet (but my tests showed me multiple worksheets).
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question