Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6023333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:59:22+00:00 2026-05-23T03:59:22+00:00

I am working with some code that uses an OleDbConnection to load data from

  • 0

I am working with some code that uses an OleDbConnection to load data from an Excel file to a DataTable. Currently it defaults to the first Sheet but getting it’s name using the following code:

string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=myFilename.xlsx;Extended Properties=""Excel 12.0 Xml;HDR=YES"""

DataTable = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
if (schemaTable.Rows.Count > 0)
    return schemaTable.Rows[0]["TABLE_NAME"].ToString();
else
    return "Sheet1$"

This has been working fine until recently when the Excel document (we are receiving from a third party) started containing named Ranges. I’m there are no hidden sheets that I can find.

Now

schemaTable.Rows[0]["TABLE_NAME"].ToString()

returns the name of the first Range.

Is there something different I can do with my schemaTable object to identity just the sheets and not the named Ranges in the sheet?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:59:22+00:00Added an answer on May 23, 2026 at 3:59 am

    Is the use of OleDbConnection mandatory or you can switch to other options (DAO for instance) ?

    alternative solution 1 : using interop :

        Private Function GetSheetNames(ByVal path As String)
        Dim lst As New List(Of String)
        'Note: this will not work for Excel 2007 (.xlsx) workbooks.
        If IO.File.Exists(path) AndAlso IO.Path.GetExtension(path) = ".xls" Then
        Dim app As New Excel.Application
        Dim WB As Excel.Workbook
        Try
           WB = app.Workbooks.Open(Filename:=path)
           If WB IsNot Nothing Then
             For Each ws As Excel.Worksheet In WB.Sheets
               lst.Add(ws.Name)
             Next
             WB.Close()
             System.Runtime.InteropServices.Marshal.ReleaseComObject(WB)
             WB = Nothing
           End If
        Catch ex As Exception
           MessageBox.Show(ex.Message)
        Finally
           System.Runtime.InteropServices.Marshal.ReleaseComObject(app)
           app = Nothing
        End Try
         End If
         Return lst
    End Function
    

    Source : http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/21d3f77c-1d3d-44e0-9bd5-eca45a0affa6

    Alternative solution 2 : using DAO :

    Dim dao_dbE As dao.DBEngine
    Dim dao_DB As dao.Database
    dao_dbE = New dao.DBEngine
    Dim sheetsNames As List(Of String) = New List(Of String)()
    dao_DB = dao_dbE.OpenDatabase(completeFileName, False, True, "Excel 8.0;")
    For i As Integer = 0 To dao_DB.TableDefs.Count - 1
        sheetsNames.Add(dao_DB.TableDefs(i).Name)
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some working code that uses IImgCtx to load images, but I can't
I'm working on some code that uses the System.Diagnostics.Trace class and I'm wondering how
I'm working with some code that widely uses the idiom of returning a pointer
I have been working on some legacy C++ code that uses variable length structures
I'm working on some code that uses a lot of after_save callbacks, and I
Greetings, I'm working with a vendor who has implemented some code that uses a
I'm currently working on an application that uses py2exe to make an exe file
I'm working on some C++ code that uses libsigc++ for signaling (eventing.) I'm quite
I am working on editing some old C++ code that uses global arrays defined
I'm working on some code that uses Open Dynamics Engine . I've worked with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.