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 7890921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:28:57+00:00 2026-06-03T06:28:57+00:00

I have a vb program that reads data from an excel sheet and displays

  • 0

I have a vb program that reads data from an excel sheet and displays it in a datagridview. The problem with this program is that it is able to read the data and display it only when the excel file is opened but when the excel file is not opened, it gives an error report that

System.Data.OleDb.OleDbException: External table is not in the expected format.
at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.OleDb.OleDbConnection.Open()
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at mForm.Form1.Button1_Click(Object sender, EventArgs e) in D:\myWorld\projects\coffee\mForm\mForm\Form1.vb:line 16

Is there a way to be able to read from this file even when it is not opened? Here is the code I use to get the data and put in the datagridview:

`Try
        Dim MyConnection As System.Data.OleDb.OleDbConnection
        Dim DtSet As System.Data.DataSet
        Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
        MyConnection = New System.Data.OleDb.OleDbConnection _
        ("Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & Application.StartupPath & "\Staff Contracts.xlsx; Extended Properties=Excel 8.0")
        MyCommand = New System.Data.OleDb.OleDbDataAdapter _
            ("select * from [Staff Contracts$A3:K14]", MyConnection)
        MyCommand.TableMappings.Add("Table", "TestTable")
        DtSet = New System.Data.DataSet
        MyCommand.Fill(DtSet)
        DataGridView1.DataSource = DtSet.Tables(0)
        MyConnection.Close()
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try`
  • 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-06-03T06:28:58+00:00Added an answer on June 3, 2026 at 6:28 am

    It looks like you are using an Excel 2003 connection string for an Excel 2007 file. Try using a connection string like this:

    var connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=""Excel 12.0;HDR=YES"""
    

    I use this code to read excel files server side (no need for Microsoft Office Install):

    Public Function getData(selectCmd As String, filePath as string) As System.Data.DataTable
        Dim dataTable As New DataTable()
        Using conn As New OleDbConnection(connString)
            Dim adapter As New OleDbDataAdapter(selectCmd, conn)
            adapter.Fill(dataTable)
        End Using
        Return dataTable
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem: I have a datagridview that reads the data from a
We have an asp.net c# program that reads a sheet from an Excel file
I have a program that reads data from a file line-by-line. I would like
I have a simple program that reads data from a PNG into a 2D
I have a program that reads arbitrary data from a file system and outputs
I have a program that should read from a file.It reads some amount of
I have a program that takes data from an excel file and manipulates it
actually i have a java program that reads the data from a specific XML
I have a server program that reads data from a remote stream via TCP,
I have a small program that reads in a file and processes the data

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.