Change the Data type in the Data Set so that Excel sheet population works fine

Hi experts,

I was asked to create a report in Excel. I should take data from a table and populate it on Excel.

I used the below query
select * from database_table;
Now in database there is a column name "ID" and its data type is  number.

Since some of the ID data is large, and after populating them in excel, they get converted to some different representation.

for example the value 9999999999999 in excel becomes

I am asked to change the data type of this value to String in .net end, i.e they dont want me to use "select to_char(ID),.... from database_table". They wanna keep select * from database_table. but need to change the data type for column to string.

Any idea how do I do this. Is there a property like dataset.column.datatype = text

I think we can do it by changing the column property of the excel sheet to "General" or "Text".
But can this be done using .net side

Thanks very much,

this.sQuery="select * from database_table"
IDataReader IReader = objConn.ExecuteReaderII("SECURITY", this.sQuery, true);
DataSet obj = new System.Data.DataSet ();
obj.Load(IReader, System.Data.
LoadOption.OverwriteChanges, new string[] { "available" });
                                                      //need to change this obj dataset's ID column to string.
if (obj.Tables.Count > 0)
if (!Cache.ContainsKey("report"))
Cache.Add("report", obj);
"report"] = obj;

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

anyoneisSoftware DeveloperCommented:
You can't change the type of a column once it is in a I think the easiest solution is to change the select so that you convert the ID to a string - which means you can't do the "Select *", but must name the columns.

If they can tolerate a new column, say, "StringID", then all you have to do is add a column of type string to the datatable, and set it to an expression.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace ReplaceColumn
    class Program
        static void Main(string[] args)
            // Simulate the creation of the dataset
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            DataColumn dc = new DataColumn("Id", typeof(int));
            dc = new DataColumn("Value", typeof(double));
            dt.Rows.Add(1, 1.1);
            dt.Rows.Add(2, 2.2);
            dt.Rows.Add(3, 3.3);
            // OK, now that we have a dataset with data, add a column 
            dc = new DataColumn("IdAsString", typeof(string), "Id");

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
techbieAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.