Changing DataCOlumn DataType

G

George

Hi,

I need to change the datatype of a datacolumn from Int16
to Int32 under certain conditions at runtime. The problem
is that the table is already populated with data, although
the data in the column to change can be removed.

I have got this working by removing the datacolumn from
the datatable, (this clears all data in the column) and
then changing the datatype before adding it again. Problem
with this is the column is added at the end.

Can a datacolumn be added back to it original position?
Or, is there another way of doing this?

Many thanks.
 
M

Miha Markic [MVP C#]

Hi George,

No, once data is inside the column you can't change its type.
Why does it matter its position?
 
A

Andrew Conrad

Try creating an expression column with the datatype required and add a
simple expression that simply points to the original column. As long as
the types can be converted, you can progamaticly add expression columns
after data has been added.

Andrew Conrad
Microsoft Corp
http://blogs.msdn.com/aconrad/
 
M

Miha Markic [MVP C#]

However, you can't modify expression column value which might be important
for databinding.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top