467,228 Members | 1,439 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,228 developers. It's quick & easy.

Q: changing the datatype of a column in a datatable

Hi

Is it possible to change the type of data a column holds in DataTable at
runtime? For example, suppose that the table column originally holds
Strings, can we, at runtime, change it to Integers?

I'm also interested in changing the date/time that may be held in a column.
That is, if the date and time are held in a column of DataTable, how can we
change it so it only has the time?

Geoff
Nov 20 '05 #1
  • viewed: 1993
Share:
1 Reply


--

W.G. Ryan, eMVP

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/...ity/newsgroups
"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40*********************@news.dial.pipex.com.. .
Hi

Is it possible to change the type of data a column holds in DataTable at
runtime? Yes, just change the DataType property
http://msdn.microsoft.com/library/de...classtopic.asp
However, if anything is in the column that can't be converted, you'll raise
an exception
For example, suppose that the table column originally holds Strings, can we, at runtime, change it to Integers?

I'm also interested in changing the date/time that may be held in a column. That is, if the date and time are held in a column of DataTable, how can we change it so it only has the time? For this I'd create an expression column, add it to the datatable and use
it. There is not a Time type per se although there is a Timespan but I
doubt that's what you want. You could use a string and format it with the
Expression and that would probably work. If you check the link I posted
above you'll see the types that are supported.

Here's a link to expression syntax
http://msdn.microsoft.com/library/de...ssionTopic.asp
and here's an example I wrote
http://www.knowdotnet.com/articles/dataviews1.html
HTH,

Bill
Geoff

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Jon Brunson | last post: by
1 post views Thread by Rippo | last post: by
2 posts views Thread by wapsiii | last post: by
reply views Thread by Adict | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.