473,480 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How do I check the type of the value represented in a system.type?

Don
I have an array of System.type and I need to go through the array and
perform different logic depending on the type stored in the array.

I want to do:
if (typeof typeCollection(i) is String) then
'some logic
elseif (typeof typeCollection(i) is int32) then
'some logic
.....

The problem is the type of my object is always system.type. If I
toString it I get the text that represents the data type but I don't
really like string comparisions when I'm trying to determine type.

I am storing the type of data from a dataColumn in this array as
follows:
typeCollection.add(dataColumn.dataType())

I then add the array to the viewState so I can access the data after a
postback.

Thanks,
Don

Nov 19 '05 #1
5 1820
Don,

I think you need to store your items as an array of System.Object instead of
System.Type. Then when you check them you won't always get back System.Type.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Don" <ch*********@hotmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
I have an array of System.type and I need to go through the array and
perform different logic depending on the type stored in the array.

I want to do:
if (typeof typeCollection(i) is String) then
'some logic
elseif (typeof typeCollection(i) is int32) then
'some logic
....

The problem is the type of my object is always system.type. If I
toString it I get the text that represents the data type but I don't
really like string comparisions when I'm trying to determine type.

I am storing the type of data from a dataColumn in this array as
follows:
typeCollection.add(dataColumn.dataType())

I then add the array to the viewState so I can access the data after a
postback.

Thanks,
Don

Nov 19 '05 #2
Don
I have a DataTable filled with data from the database which I bind to
the datagrid. On post back I need to be able to determine the data
type for each cell on the selected row.

To do this I iterate through the columns in the data table and add the
type of each column to the array as shown below:
dim col as datacolumn

for each col in datatable.column
typeCollection.add(col.DataType())
next

I can't add the column to the array because it is not serializable and
I need to store it in the ViewState. I don't have an actual object to
add to the array. I could iterate through the first row and add that
object to the array but I still need the DataTypes when I have no rows
returned.

Nov 19 '05 #3
Don,

Ahhhh, didn't know that. I think you could do this:

Going with what you said earlier about ToString working go ahead and store
each column type using ToString

typeCollection.add(col.DataType().ToString)

But then when you do your comparison use the System.Type object's GetType
method.

If (System.Type.GetType(typeCollection(i).toString) Is String) Then

The System.Type.GetType function returns a type based on the string name.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Don" <ch*********@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
I have a DataTable filled with data from the database which I bind to
the datagrid. On post back I need to be able to determine the data
type for each cell on the selected row.

To do this I iterate through the columns in the data table and add the
type of each column to the array as shown below:
dim col as datacolumn

for each col in datatable.column
typeCollection.add(col.DataType())
next

I can't add the column to the array because it is not serializable and
I need to store it in the ViewState. I don't have an actual object to
add to the array. I could iterate through the first row and add that
object to the array but I still need the DataTypes when I have no rows
returned.

Nov 19 '05 #4
Don
This does not work. As you stated GetType returns a type based on the
string name and I already have that in the typeCollection in array.
The problem is that the type of this obejct is System.Type not
System.String so I can't do the typeOf operation.

Nov 19 '05 #5
Don,

Did you try it?

Works fine for me.

Here's the code I used, run it and see.

Dim DataTable1 As New DataTable

DataTable1.Columns.Add(New DataColumn("Column1", GetType(String)))

DataTable1.Columns.Add(New DataColumn("Column2", GetType(Int32)))

DataTable1.Columns.Add(New DataColumn("Column3", GetType(Object)))

DataTable1.Columns.Add(New DataColumn("Column4", GetType(DateTime)))

Dim ArrayList As New ArrayList

For Each Column As DataColumn In DataTable1.Columns

ArrayList.Add(Column.DataType.ToString)

Next

Dim ColumnCount, ColumnLoop As Int32

ColumnCount = ArrayList.Count - 1

Dim TypeString As String

For ColumnLoop = 0 To ColumnCount

If System.Type.GetType(ArrayList(ColumnLoop).ToString ) Is GetType(Int32)
Then

Response.Write("Int32 Found in Column " & ColumnLoop.ToString)

End If

Next
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Don" <ch*********@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
This does not work. As you stated GetType returns a type based on the
string name and I already have that in the typeCollection in array.
The problem is that the type of this obejct is System.Type not
System.String so I can't do the typeOf operation.

Nov 19 '05 #6

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

Similar topics

8
2214
by: Rade | last post by:
Following a discussion on another thread here... I have tried to understand what is actually standardized in C++ regarding the representing of integers (signed and unsigned) and their conversions....
7
1513
by: Starx | last post by:
I am writing a fraction class and I was testing my addition operator to find out how big the numerator and denominator can be before an overflow occurs. I was doing it like this: fraction...
51
4446
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
4
7713
by: Stan R. | last post by:
Hello, I have xmllint and xsltproc installed and running on both my linux and win32 platforms, all seems good. I have a couple questions though. 1) If I have an external dtd file, which is...
7
9800
by: Harris | last post by:
Dear all, I have the following codes: ====== public enum Enum_Value { Value0 = 0, Value1 = 10,
11
3512
by: aisling.cronin | last post by:
Hi I am using ctime to convert the following string 1144412677847 .... Please could some one to double check if they get the same result as me (The Time is Sun Nov 02 09:11:51 2031). It seems...
6
3386
by: Dan Henry | last post by:
I need a sanity check. The following is an exchange on comp.arch.embedded with CBFalconer in a rather long MISRA related thread. Since my little section of that thread and area of interest was...
4
3219
by: Giff | last post by:
Hi, I have a function that takes in a float and then performs a division. Since I know that it is impossible to check if the value I pass is equal to zero (being a float), I don't perform any...
55
3248
by: lovecreatesbea... | last post by:
Do you check all error conditions for all library calls in you code? Is it necessary to check all errors? Is it convenient to check all errors (or how to make code clean and readable with mass of...
0
7054
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,...
0
7057
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
7003
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...
0
5357
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4798
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...
0
4495
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3008
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...
1
570
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
199
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...

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.