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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:00:21+00:00 2026-06-15T08:00:21+00:00

This is my problem: I’m reading data from an Excel file on a .NET

  • 0

This is my problem:

I’m reading data from an Excel file on a .NET MVC app, what I’m doing is to read all data from the excel and then loop over each record inserting the data contained in the record into my business model.

All works perfectly. However, I’ve found that one field, sometimes, return an empty string when retrieved from the excel. Curiously this field can contain a simple string or a string that will be treated as an array (it can include ‘|’ characters to build the array) on some excel files the field returns empty when the ‘|’ char is present and in others when it isn’t, and this behaviour is consistent all along that file.

There are other fields that can receive the separator and work always ok. The only difference between both fields are that the working ones are pure strings and the one that’s failing is a string of numbers with possibles ‘|’ separating them.

I’ve tried to change the separator character (I tried with ‘#’ with same results) and to specifically format the cells as text without any success.

This is the method that extracts data from the excel

private DataSet queryData(OleDbConnection objConn) {
    string strConString = "SELECT * FROM [Hoja1$] WHERE NUMACCION <> ''";
    OleDbCommand objCmdSelect = new OleDbCommand(strConString, objConn);
    OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
    objAdapter1.SelectCommand = objCmdSelect;
    DataSet objDataset = new DataSet();
    objAdapter1.Fill(objDataset, "ExcelData");
    return objDataset;
}

I first check the fields from the excel with:

fieldsDictionary.Add("Hours", table.Columns["HOURS"].Ordinal);

And later, when looping through the DataSet I extract data with:

string hourString = row.ItemArray[fieldsDictionary["Hours"]].ToString();

This hourString is empty in some records. In some Excel files it’s empty when the record contains ‘|’, on others it’s empty when it doesn’t. I haven’t found yet a file where it returns empty on records of both classes.

I’m quite confused about this. I’m pretty sure it has to be related to the numerical nature of field data, but cannot understand why it doesn’t solve when I force the cells on the excel file to be “text”

Any help will be more than welcome.

  • 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-15T08:00:22+00:00Added an answer on June 15, 2026 at 8:00 am

    Ok. I finally solved this.

    It seems like Excel isn’t able to recognize a whole column as same data type if it contains data of possibly different classes. This happens even if you force the cell format to be text on the workbook, as when you query the data it will recognize the field as a determinated type according to the first record it receives; that was the reason why different files emptied different type of records, files starting with a plain text emptied numeric values and vice versa.

    I’ve found a solution to this just changing the connection string to Excel.

    This was my original connection string

    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=pathToFile;Extended Properties="Excel 8.0;HDR=Yes;"
    

    And this the one that fixes the problem

    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=pathToFile;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1"
    

    The parameter IMEX=1 states to excel that it must manage all mixed data columns as plain text. This won’t work for you if you need to edit the excel file, as this parameter also opens it on read-only mode. However it was perfect for my situation.

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

Sidebar

Related Questions

This problem is baffling me: BEGIN; INSERT INTO sub_users(user_id, email) SELECT user_id FROM users
This problem is similar to my previously asked question. When I query data using
This problem crops up every now and then at work. Our build machine can
This problem has been driving me nuts all day and there has to be
This problem has been KILLING me. I've been working on this app for 8
this problem is driving me really mad. In an Asp.Net-application, I have two DropDownLists,
This problem seemingly appeared from nowhere, and it's been turning me insane for the
This problem is same as asked in here . Given a list of coins,
This problem seems very simple to me, but I've been unable to fix it,
This problem is caused by my acknowledge of English and jQuery or maybe something

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.