By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,077 Members | 1,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,077 IT Pros & Developers. It's quick & easy.

Q: changing the datatype of a column in a datatable

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a


--

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.