Problem checking data type of a db column

R

RichardF

I a m trying to loop through the columns in my DataTable and do
different things based on the data type of each column.

For testing purposes I tried the following code...

Dim MyColumn As DataColumn
MyColumn = MyDataSet.Tables("MyTable").Columns"MyColumn")

Dim MyType As System.Type
MyType = MyColumn.DataType

Debug.WriteLine(MyType.ToString)
Debug.WriteLine(Convert.GetTypeCode(MyType) = TypeCode.Boolean)

In the output window I get the following...

System.Boolean
False


What is happening? How can I checl to see if my column is a boolean
column.

Thanks for any help!

RichardF
 
W

W.G. Ryan eMVP

This should work for you:

DataColumn BooleanColumn = new DataColumn("BooleanTestColumn",
typeof(System.Boolean));

Type myType = BooleanColumnColumn.DataType;

if(myType == typeof(System.Boolean)){

Console.WriteLine("It Worked");//You will get here.

}
 
M

Marvin Varela

I think you could use:

Debug.WriteLine(GetType(System.Boolean) Is MyType)

This should return true.

Hope thsi helps.
 
M

Marvin Varela

I used exactly the following code and it returned true:

Dim MyColumn As DataColumn

MyColumn = DataSet11.Tables("Table").Columns("Active")

Dim MyType As System.Type

MyType = MyColumn.DataType

Debug.WriteLine(MyType.ToString())

Debug.WriteLine(GetType(System.Boolean) Is MyType)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top