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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:49:38+00:00 2026-05-31T22:49:38+00:00

I am trying to retrieve DataTable from .xls file. Below are my code: OleDbConnection

  • 0

I am trying to retrieve DataTable from .xls file. Below are my code:

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;");

//path is where the .xls file located
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() + "] order by Material", MyConnection);
DtSet = new System.Data.DataSet();

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

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

Problem is: I have some inconsistent rows in my table, meaning they don’t follow the other rows datatype.

Let’s say in column A, I have cells that are supposed to be like:

105161610

146161701

196171717

………

Meaning to say it’s supposed to be of Int32 datatype.

These are the majority of the column cells..

I also have some other cells (still in the same column) that look like:

ABC9012

KDJ0981

KLP0001

…….

They somehow follow string datatype.

When I execute the code, I can only Select cells of int type while cells having the other type (string) is set to null instead. Although in my code I basically set the select * explicitly.

Can someone advise me on how to consistently retrieve both kind of datatype (instead of only 1 like what happens now)?

  • 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-31T22:49:39+00:00Added an answer on May 31, 2026 at 10:49 pm

    You have to cast or convert both types of data to SQL equivalent of string like varchar.

    Try either one of the following:

    1. select cast(Column_A as varchar) Column_A from TableName order by Material 
    2. select convert(varchar, Column_A) Column_A from TableName order by Material
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying retrieve user name from the code through graph api, the below
I'm trying to retrieve a file from a server using SFTP (as opposed to
I am trying retrieve data from a .php file on a server from within
I am trying to retrieve the file from sharepoint to local hard disk. Here
I've been having problems trying to retrieve data from my database to a DataTable
Iam trying to retrieve data from mysql database into stylesheet.php but it is not
I'm trying to retrieve an XML stream from a URL. For most URLs my
I'm trying to retrieve data from an SQL Server 2000 server, and place into
I'm trying to retrieve the SubItem in my ListView from another thread, but I
I am trying to retrieve the correct value from an ArrayList of objects (.NET

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.