?
Solved

ADO.Net - Excel - 1st Worksheet

Posted on 2009-06-29
3
Medium Priority
?
392 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 1600 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 400 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

752 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