Solved

ADO.Net - Excel - 1st Worksheet

Posted on 2009-06-29
3
373 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
Comment Utility
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
Comment Utility
0
 
LVL 69

Author Comment

by:Éric Moreau
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now