Check to see DataColumn DataType is Boolean?

J

Jay Balapa

Hello,

Iam trying to do the following-

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

this does not work either Type.GetType("System.Boolean") instead of
typeof(bool).

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

Is there a workaround?

Thanks.
jay
 
B

Bjorn Abelli

...
Iam trying to do the following-

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

this does not work either Type.GetType("System.Boolean")
instead of typeof(bool).

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

Both ways "should" work, or at least not give that error.

Or you're talking about another type of DataColumn than an instance of
System.Data.DataColumn...

I believe the error must lie somewhere else in your code.

Could you provide a short code snippet that in your meaning "should"
compile, but doesn't?

This compiles and runs fine:

using System;
using System.Data;

class DataColumnTest
{
static void Main(string[] args)
{
DataColumn myColumn = new DataColumn();
myColumn.DataType = typeof(string);

if(myColumn.DataType == typeof(bool))
{
Console.WriteLine(true);
}
else
{
Console.WriteLine(false);
}
}
}


/// Bjorn A
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top