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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:57:54+00:00 2026-05-16T11:57:54+00:00

Im reading a xlsx file as a db to do some work i noticed

  • 0

Im reading a xlsx file as a db to do some work

i noticed that its reading some feilds in as int and date even though i just want it all to come in as text . is there anyway to override this feature?

Code below

(feel free to point out anything i could be doing better with my code as well)

  private DataSet ExceltoDT(OpenFileDialog dialog)
    {
        try
        {
            string connst = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dialog.FileName + ";Extended Properties=\"Excel 12.0 Xml;HDR=NO\";";
            string sheet = "Sheet1$";
            string strSQL = "SELECT * FROM [" + sheet + "]";
            //string Table = "081710";
            OleDbConnection xlsdb = new OleDbConnection(connst);
            xlsdb.Open();
            OleDbDataAdapter adp = new OleDbDataAdapter(strSQL, xlsdb);
            DataSet ds2 = new DataSet();
            adp.Fill(ds2);


            adp.Dispose();
            xlsdb.Close();
            xlsdb.Dispose();

            return ds2;
        }
        catch (StackOverflowException stack_ex2)
        {
            MessageBox.Show("(2007 Excel file) Stack Overflowed!" + "\n" + stack_ex2.Message);
            return null;

        }
        catch (OleDbException ex_oledb2)
        {
            MessageBox.Show("An OleDb Error Thrown!" + "\n" + ex_oledb2.Message);
            return null;
        }
    }
  • 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-16T11:57:55+00:00Added an answer on May 16, 2026 at 11:57 am

    Add a ' (apostrophe) in front of every cell value. That will tell Excel “Treat this as text even when it looks like a number/date/whatever”.

    Not what you want? Then don’t use the DB connector because it’s badly broken. You’ll notice that when you have a column with cells that are mixed. In that case, the DB driver will look at the first 8 rows and set the type to the majority of types it finds and return NULL for anything in that column that doesn’t fit. You can fix that by hacking your registry.

    Instead use the OLE API to open the Workbook and then start from there, reading row by row, converting the data as you need (this long list of posts should contain about every possible way to access Excel from C# plus all the bugs and problems you can encounter).

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

Sidebar

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.