473,399 Members | 2,278 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,399 software developers and data experts.

Creating a column of my own datatype in a datatable.

UJ
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.
Mar 13 '06 #1
4 3126
UJ,

Why not just use an integer (or other appropriate data type, depending
on the enumeration) as the underlying data type? You could use a string,
but I would only recommend that if the values behind the names are fluid,
and change often.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"UJ" <fr**@nowhere.com> wrote in message
news:Ou**************@tk2msftngp13.phx.gbl...
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.

Mar 13 '06 #2
UJ
I'm confused - I've got a datatype defined as:

public enum Rebooter
{
NoOne,
WatchDog,
Dispatcher
};

and I would like a column in my datatable that I can use to represent that.
(This datatype get's used in a lot of places in the programs.) So I'm not
sure what your suggesting to do. Store it as an integer and keep converting
it back and forth?

TIA - Jeff.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:OW**************@TK2MSFTNGP09.phx.gbl...
UJ,

Why not just use an integer (or other appropriate data type, depending
on the enumeration) as the underlying data type? You could use a string,
but I would only recommend that if the values behind the names are fluid,
and change often.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"UJ" <fr**@nowhere.com> wrote in message
news:Ou**************@tk2msftngp13.phx.gbl...
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.


Mar 13 '06 #3
Hi,

You can use set it as int and cast it back when retrieving the value

at the end you will always need to cast it back to the correct type

additionally you could try
DataColumn( "theColumn", typeof(System.Enum) )

But I have never tried the above, so no idea if it will work or not

an Int is the best option I think
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"UJ" <fr**@nowhere.com> wrote in message
news:Ou**************@tk2msftngp13.phx.gbl...
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.

Mar 13 '06 #4
UJ,

Pretty much. Converting from an integer isn't a big deal at all, you
can just cast it. If you stored it as a string, it would be much, much more
difficult, since you would have to make a method call, and not just perform
a cast.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"UJ" <fr**@nowhere.com> wrote in message
news:uC**************@tk2msftngp13.phx.gbl...
I'm confused - I've got a datatype defined as:

public enum Rebooter
{
NoOne,
WatchDog,
Dispatcher
};

and I would like a column in my datatable that I can use to represent
that. (This datatype get's used in a lot of places in the programs.) So
I'm not sure what your suggesting to do. Store it as an integer and keep
converting it back and forth?

TIA - Jeff.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:OW**************@TK2MSFTNGP09.phx.gbl...
UJ,

Why not just use an integer (or other appropriate data type, depending
on the enumeration) as the underlying data type? You could use a string,
but I would only recommend that if the values behind the names are fluid,
and change often.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"UJ" <fr**@nowhere.com> wrote in message
news:Ou**************@tk2msftngp13.phx.gbl...
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.



Mar 13 '06 #5

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

Similar topics

8
by: Nanda | last post by:
hi, I am trying to generate parameters for the updatecommand at runtime. this.oleDbDeleteCommand1.CommandText=cmdtext; this.oleDbDeleteCommand1.Connection =this.oleDbConnection1;...
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...
6
by: Robert Schuldenfrei | last post by:
Dear NG, After being away from C# programming for a spell, I am trying my hand at what should be a simple task. I have been hitting my head against the wall this morning. I have a simple order...
2
by: ad | last post by:
I want to add a Column to a DataTable. I use the codes below; I want the Column dc to be a type of Boolean. How can I assign the DataType? ...
1
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...
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...
4
by: Jeff | last post by:
I am stuck on trying to generate two columns headers for a datagrid on form load. I can use a datatable as the datasource and get the results I want, but I want to set different column widths and...
3
by: Oenone | last post by:
I have a project that creates a SqlDataAdapter and uses its Fill method to fill a DataTable with data from a user-provided query. From there I can obviously access details about the rows and...
5
by: Ken | last post by:
I'm trying to run a loop to capture column property information from a table in my datasource. Can anybody see where this is going wrong? Dim tbl As New DataTable Dim col As DataColumn Dim x...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.