473,387 Members | 1,844 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,387 software developers and data experts.

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
1 2216


--

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Jon Brunson | last post by:
Is it possible to use a DataAdapter to fill a DataTable, change the DataColumns of that DataTable (and maybe even it's name) and then commit those changes to the database (in my case SQL Server...
2
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...
1
by: Rippo | last post by:
I am returning a datatable from a stored procedure and then iterating through the columns. I am trying to find out if a column has the sql data type of ntext. In .net the datatype of a sql ntext...
2
by: Griff | last post by:
When attempting to change the datatype for a datatable column with the following code: dtap.Columns(4).DataType = system.Type.GetType"System.String") I keep getting an error that says that I...
6
by: Sam | last post by:
Hi Here is my code : Code: Dim dt As New DataTable dt.Columns.Add.ColumnName = "New" dt.Columns("New").DataType = System.Type.GetType("System.String") dt.Columns.Add.ColumnName = "Id"...
7
by: Simon Verona | last post by:
I posted this in dotnet.languages.vb.controls but thought I'd post here as well.. I have a combobox that is bound to a dataview generated from a dataset. The dataset has a single table...
2
by: wapsiii | last post by:
How do I query the datatype of a column in a datatable (Ineed to find the smalldatetime datatypes in a ms sql produced datatable). I'm trying this, but is isn't quite right: For i As Byte = 0...
4
by: UJ | last post by:
I have a datatype that I want to use as a type for a column (It's an enumeration.) but I can't get the syntax right. Can you even do it? Or do I need to do it as a string and convert it back and...
1
by: keithb | last post by:
The following code sets a DataTable column DataType to "String" column.DataType = System.Type.GetType("System.String"); What is the corresponding statement when the data type is boolean? I...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.