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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:33:54+00:00 2026-06-15T00:33:54+00:00

I need to retrieve data from an Excel file and insert the data into

  • 0

I need to retrieve data from an Excel file and insert the data into a database. Im trying now to just retrieve the data but i keep getting an HRESULT:0x800A03EC exception error.

my code:

  public void ReadFile()
        {
            try
            {
                Excel.Application ep = new Excel.Application();
                Excel.Workbook ewb = ep.Workbooks.Open(@"C:/Temp/Copy of AGCO Transport Schedule.xlsx");
                Excel.Worksheet ews = ewb.Sheets[1];
                Excel.Range range = ews.UsedRange;

                int rowCount = range.Rows.Count;
                int columnCount = range.Columns.Count;

                for (int i = 1; i < rowCount; i++)
                {
                    for (int j = 1; j < columnCount; j++)
                    {
                      string  str = (string)(range.Cells[i, j] as Excel.Range).Value2;
                        Console.WriteLine(str);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("YOLO "+e.Message);
            }
        }
    }

After getting the solution for the code above from a user here. The loop indexes should be changed to 1 instead of 0. I have corrected the code above. But the thing is that I need to select only 2 columns from the data in Excel, so i went on using sql for retrieving the data from the Excel file. But this time i keep getting “failed to create file” error and this happens when i try to open my connection.

my code:

public void ReadExcelFile()
{
    string connectionString = string.Format(ConfigurationManager.ConnectionStrings["ExcelConnection"].ConnectionString.Replace("'", "\""), "@C:/Temp/Copy.xlsx");
    using (OleDbConnection connection = new OleDbConnection(connectionString))
    {
        try
        {
            connection.Open();
            string sqlCmd = "SELECT  * FROM [Ark1$]";
            using (OleDbCommand command = new OleDbCommand(sqlCmd, connection))
            {
                command.CommandType = System.Data.CommandType.Text;
                using (OleDbDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Console.WriteLine(reader.ToString());
                    }
                }
            }

        }
        catch (Exception exception)
        {
            Console.WriteLine("ERROR in ReadExcelFile() method. Error Message : " + exception.Message);
        }
    }
}

can anyone help me with this ?

  • 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-15T00:33:55+00:00Added an answer on June 15, 2026 at 12:33 am

    Something i would like to add:
    Your method is SLOW – really, really slow.
    To speed it up, you have two alternatives:
    Use EPPLUS, it is a fast and free library for excel reading/writing.
    Oder get the data from excel in one go, simply “pull” the data from your range object into an array (dim values() = range.value2 in VB.net) and iterate over that array. That is a lot faster than enumerating each cell.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to retrieve data from several rows and then insert the results into
I need to retrieve the data information from a database and bind the image
I need to export data from php (data retrieved from mysql database) to excel.
I need to retrieve data from the DOM, but the containers have no a
Hello I need to retrieve data from database via an ajax call. I am
I need to retrieve some data from a remote database, it is a kind
I need to retrieve data from two tables. the first is a list of
I have a situation where I need to retrieve data from a query which
Im stumbling upon a problem where i need to retrieve data from the following
using jquery I need to retrieve an array from table cells, format 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.