473,395 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Cannot change DataType of a column once it has data.

ad
I use ado.net to fill a Excel wroksheet into a DataTable.

The data in the Excel wroksheet is digital.
After the data filled into the DataTable, the DataType of each column is set
to
Double, but I want to treat them as string, I use the code to covert them

DataTable dt = ds.Tables0];
int iColCount = dt.Columns.Count;
for (int j = 0; j < iColCount; j++)
{
DataColumn myDC = dt.Columns[j];
myDC.DataType = System.Type.GetType("System.String");
}

But it fail with message Cannot change DataType of a column once it has
data.

How can I do?
Nov 17 '05 #1
2 45841
ad wrote:
I use ado.net to fill a Excel wroksheet into a DataTable.

The data in the Excel wroksheet is digital.
After the data filled into the DataTable, the DataType of each column is set
to
Double, but I want to treat them as string, I use the code to covert them

DataTable dt = ds.Tables0];
int iColCount = dt.Columns.Count;
for (int j = 0; j < iColCount; j++)
{
DataColumn myDC = dt.Columns[j];
myDC.DataType = System.Type.GetType("System.String");
}

But it fail with message Cannot change DataType of a column once it has
data.

How can I do?

-----------------------------------------------------------------------
-----------------------------------------------------------------------

Do the following in this part:
DataColumn myDC = dt.Columns[j];
myDC.DataType = System.Type.GetType("System.String");


!!! Use this instead !!!!
-----------------------------------------------------------------------

DataColumn myDC = new
DataColumn(dt.Columns[j].ColumnName,System.Type.GetType("System.String"));

-----------------------------------------------------------------------
-----------------------------------------------------------------------

de*******@freelancedotnetdeveloper.com
http://www.freelancedotnetdeveloper.com
Providing consultancy services in .NET
Nov 17 '05 #2
ad wrote:
I use ado.net to fill a Excel wroksheet into a DataTable.

The data in the Excel wroksheet is digital.
After the data filled into the DataTable, the DataType of each column is set
to
Double, but I want to treat them as string, I use the code to covert them

DataTable dt = ds.Tables0];
int iColCount = dt.Columns.Count;
for (int j = 0; j < iColCount; j++)
{
DataColumn myDC = dt.Columns[j];
myDC.DataType = System.Type.GetType("System.String");
}

But it fail with message Cannot change DataType of a column once it has
data.

How can I do?

-----------------------------------------------------------------------
-----------------------------------------------------------------------

Do the following in this part:
DataColumn myDC = dt.Columns[j];
myDC.DataType = System.Type.GetType("System.String");


!!! Use this instead !!!!
-----------------------------------------------------------------------

DataColumn myDC = new
DataColumn(dt.Columns[j].ColumnName,System.Type.GetType("System.String"));

-----------------------------------------------------------------------
-----------------------------------------------------------------------

de*******@freelancedotnetdeveloper.com
http://www.freelancedotnetdeveloper.com
Providing consultancy services in .NET
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: c duden | last post by:
I am able to add an exisiting office addin project to a blank solution in VS.NET 2003. When I attempt to add it's setup project I get the following error in VS.NET "Cannot change threading mode...
5
by: Hardy Wang | last post by:
Hi all, I am just wandering, is it possible to programmatically detect each column's data type of SalDataReader, DataSet.Tables, DataTable? Thanks for any suggestion! -- WWW:...
0
by: ad | last post by:
I use ado.net to fill a Excel wroksheet into a DataTable. The data in the Excel wroksheet is digital. After the data filled into the DataTable, the DataType of each column is set to Double, but...
6
by: Aaron Smith | last post by:
Ok. I have a dataset that has multiple tables in it. In one of the child tables, I have a column that I added to the DataSet (Not in the DataSource). This column does not need to be stored in the...
1
by: David Fúnez | last post by:
Hi; I'm working with Component One FlexGrid DataGrid, i've added a calculated field to the DataGrid, when i press the Save Button an error message is displayed "Cannot Change read Only...
2
by: bogie | last post by:
Hello I have some problem to change my column data type in my table property from character(15) to character(100). I use Postgresql 7.4. The problem is I try to make new column with...
1
by: raghulvarma | last post by:
table 1: eno integer primary key,ename varchar(25),salary integer table 2: dno integer primary key,eno integer references table1(eno),dname varchar(25) when I give select eno,ename,salary from...
7
by: JeremyI | last post by:
Stumped on another issue in Access 2003 (file format Access 2000) where code does not seem to do what it's supposed to based on other topics I have read. I have a form that allows the user to...
2
by: ncsthbell | last post by:
I have a string datatype column which contains values such as '1841000'. The value should be '18410'. I have tried the following: Replace(RTrim(Replace(MyValue, "0", " ")), " ", "0") The problem...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.