Check to see DataColumn DataType is Boolean?

J

Jay Balapa

Hello,

Iam trying to do the following-

if(myColumn.DataType==typeof(bool))
{
}

I get the error "Operator == cannot be applied to operands type and object
and bool."

Is there a workaround?

Thanks.
jay
 
S

Sericinus hunter

Jay said:
Hello,

Iam trying to do the following-

if(myColumn.DataType==typeof(bool))
{
}

I get the error "Operator == cannot be applied to operands type and object
and bool."

Is there a workaround?

Try Type.GetType("System.Boolean") instead of typeof(bool).
 
J

Jay Balapa

Hi Hunter,

Error states that I cannot use "==" operator period when comparing Boolean.

I have tried what you suggested and it does not work.

jay
 
S

Sericinus hunter

Jay said:
Hi Hunter,

Error states that I cannot use "==" operator period when comparing Boolean.

I have tried what you suggested and it does not work.

jay

Strange. Works for me with .Net 1.1
 
M

MSDN

This works, .NET - FW2.0

DataColumn myColumn = new
DataColumn("name",System.Type.GetType("System.Boolean"));

if (myColumn.DataType == typeof(bool))

{

if (myColumn.DataType == typeof(Boolean))

{

xxx = "okay";

}

}
 
J

Jay Balapa

Hi Miha,

Thanks for replying.

myColumn is just an iterator for a row.

foreach (DataColumn myColumn from myTable.Columns)

Thanks.
jay

Miha Markic said:
Hi Jay,

That code should work.
What is the myColumn type exactly?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Jay Balapa said:
Hello,

Iam trying to do the following-

if(myColumn.DataType==typeof(bool))
{
}

I get the error "Operator == cannot be applied to operands type and
object and bool."

Is there a workaround?

Thanks.
jay
 
M

Miha Markic [MVP C#]

Can you create a simple sample that reproduces the problem?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Jay Balapa said:
Hi Miha,

Thanks for replying.

myColumn is just an iterator for a row.

foreach (DataColumn myColumn from myTable.Columns)

Thanks.
jay

Miha Markic said:
Hi Jay,

That code should work.
What is the myColumn type exactly?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Jay Balapa said:
Hello,

Iam trying to do the following-

if(myColumn.DataType==typeof(bool))
{
}

I get the error "Operator == cannot be applied to operands type and
object and bool."

Is there a workaround?

Thanks.
jay
 
C

Cor Ligthert [MVP]

Jay,

Can you show the code as you did that,
This should in my opinion be the same in 1.x as in 2.0


Cor
 

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