470,613 Members | 2,384 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,613 developers. It's quick & easy.

Check to see DataColumn DataType is Boolean?

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


May 3 '06 #1
1 13363

"Jay Balapa" wrote...
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

May 3 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by JC Voon | last post: by
1 post views Thread by Jay Balapa | last post: by
3 posts views Thread by DaveP | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.