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

  • Home
  • SEARCH
  • 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 7718849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:16:07+00:00 2026-06-01T03:16:07+00:00

I am exporting an .xls file into datatable. Below are my code: private DataTable

  • 0

I am exporting an .xls file into datatable. Below are my code:

private DataTable ExportXlsToDt(String path)
{
    OleDbConnection MyConnection = null;
    DataSet DtSet = null;
    OleDbDataAdapter MyCommand = null;
    MyConnection = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; Data Source='" + path + "';Extended Properties=Excel 8.0;");

    ArrayList TblName = new ArrayList();

    MyConnection.Open();
    DataTable schemaTable = MyConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
    foreach (DataRow row in schemaTable.Rows)
    {
        TblName.Add(row["TABLE_NAME"]);
    }

    MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [" + TblName[0].ToString() + "]", MyConnection);
    DtSet = new System.Data.DataSet();

    MyCommand.Fill(DtSet);
    MyCommand.FillSchema(DtSet, SchemaType.Source);

    DataTable dt = new DataTable();
    dt = DtSet.Tables[0];
    MyConnection.Close();
}

However the rows after export is not as sorted as rows before export.
Example:

Original

row A

row B

row C

row D

After Export

row D

row C

row A

row B

Can someone advise me on this?

Thank’s.

  • 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-01T03:16:08+00:00Added an answer on June 1, 2026 at 3:16 am

    you have no ‘order by’ clause on your select; therefore row order isn’t guaranteed.
    Add an ‘order by’ clause to MyCommand and you should be good.

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

Sidebar

Related Questions

I'm exporting dataTable (binding dataList) to excel file calling the following method by xlsWorkBookPrepare(c:\\export.xls);
Ok. I've made this awe-crap-code Exporting table to XLS (but still no idea how
I am programmatically exporting data (using PHP 5.2) into a .csv test file. Example
I am currently exporting data from php to excel using the code as below:
I am exporting .bas files from an .xls file as outlined here: Exporting A
I'm exporting some data I have in a database into Excel. Although the below
I am exporting an aspx page as an xls (excel) file. I have everything
Exporting some data from mysql to a csv file using FasterCSV. I'd like the
When exporting a Visual Studio project to a Template (File/Export Template...) I get the
I am exporting a datatable to an excel sheet successfully... In that excel sheet

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.