473,657 Members | 2,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing datatype of a column in a datatable

When attempting to change the datatype for a datatable column with the
following code:

dtap.Columns(4) .DataType = system.Type.Get Type"System.Str ing")

I keep getting an error that says that I can't change the datatype
because there is data in the table. However, I know there is no data in
the table, as I have cleared the table and tested the results.

Please help.

Thanks
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
2 12175
Griff,

Why not just add a column and remove a column than in this case?

I would not search to long in your situation.

Cor

"Griff" <gr***@hotmail. com>
...
When attempting to change the datatype for a datatable column with the
following code:

dtap.Columns(4) .DataType = system.Type.Get Type"System.Str ing")

I keep getting an error that says that I can't change the datatype
because there is data in the table. However, I know there is no data in
the table, as I have cleared the table and tested the results.

Please help.

Thanks
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #2
Thanks. Yes that is what I'm doing just wanted to know why it didn't
work.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3

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

Similar topics

9
10909
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 2000)? Eg: Dim dc As New SqlCommand("SELECT TOP 0 * FROM SomeTable", SomeSqlConnection)
2
45879
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 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++)
1
1986
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 column is System.String. .Net also returns System.String for varchar, char, text, nvarchar and nchar. This obviously does not help me as I want to identify the ntext column I have searched for this and cannot find the answer in .net. I can...
1
2228
by: Geoff Jones | last post by:
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?
6
11256
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" dt.Columns("Id").DataType = System.Type.GetType("System.Integer")
7
4561
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 (called "Data") with two columns "Id" and "Description". Id contains a code and description contains the description that is displayed in the combobox.
2
2665
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 To dt.Columns.Count If TypeOf dt.Columns(i) Is DateTime Then ' can't find it End If Next
4
3140
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 forth? TIA - Jeff.
1
3562
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 have tried both "bit', "bool", and "boolean" and all cause an error. One would think that a simple search for "System.Type.GetType" in Books On Line would yield an answer but all I get is page after page after page of loosely unrelated...
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8742
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8621
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.