将tinyint转换为布尔值 [英] convert tinyint to boolean

查看:161
本文介绍了将tinyint转换为布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的sql表中的值设置为tinyint(不能设置为bit)。


我试图将它移动到程序中的布尔字段中尝试过:


isTrue =(int)dbReader [" IsTrue"]





isTrue = Convert.ToBoolean((int)dbReader [" IsTrue"])

两者都给我一个指定的演员阵容无效。


有没有一种简单的方法可以做到这一点


isTrue = false

if((int)dbReader [" IsTrue" ] == 1)

isTrue = true;


谢谢,


汤姆

I have a value in my sql table set to tinyint (can''t set to bit).

I am trying to move it into a boolean field in my program and have tried:

isTrue = (int)dbReader["IsTrue"]

and

isTrue = Convert.ToBoolean((int)dbReader["IsTrue"])

Both give me a "Specified cast is not valid".

Is there a simple way to do this other then

isTrue = false
if ((int)dbReader["IsTrue"] == 1)
isTrue = true;

Thanks,

Tom

推荐答案



" tshad" < ts *** @dslextreme.com写信息

新闻:%2 **************** @ TK2MSFTNGP04.phx.gbl ...

"tshad" <ts***@dslextreme.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...

>我的sql表中的值设置为tinyint(不能设置为bit)。


我试图将它移动到我的程序中的布尔字段并尝试过:


isTrue =(int)dbReader [" IsTrue"]





isTrue = Convert.ToBoolean((int)dbReader [" IsTrue"])


两个都给我一个 ;指定演员表无效。


有没有一种简单的方法可以做到这一点


isTrue = false

if((int)dbReader [" IsTrue"] == 1)

isTrue = true;
>I have a value in my sql table set to tinyint (can''t set to bit).

I am trying to move it into a boolean field in my program and have tried:

isTrue = (int)dbReader["IsTrue"]

and

isTrue = Convert.ToBoolean((int)dbReader["IsTrue"])

Both give me a "Specified cast is not valid".

Is there a simple way to do this other then

isTrue = false
if ((int)dbReader["IsTrue"] == 1)
isTrue = true;



如果((int)dbReader [" IsTrue"] ==,我不能这样做
1)





if(((int)dbReader [" IsTrue"])== 1)


我仍​​然得到同样的错误。


然而,调试器显示值为1.


谢谢,


Tom

Turns out I can''t do

if ((int)dbReader["IsTrue"] == 1)

or

if (((int)dbReader["IsTrue"]) == 1)

I still get the same error.

Yet, the debugger shows the value to be 1.

Thanks,

Tom


>

谢谢,


Tom

>
Thanks,

Tom



怎么样:


isTrue =(dbReader(" IsTrue")< 0


Tom Dacon

Dacon Software Consulting


" tshad"< ts *** @ dslextreme.comwrote in message

news:%2 **************** @ TK2MSFTNGP04 .phx.gbl ...
How about:

isTrue = (dbReader("IsTrue") <0

Tom Dacon
Dacon Software Consulting

"tshad" <ts***@dslextreme.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...

>我的sql表中的值设置为tinyint(不能设置为位)。


我试图将它移动到程序中的布尔字段中.h ave试过:


isTrue =(int)dbReader [" IsTrue"]





isTrue = Convert.ToBoolean((int)dbReader [" IsTrue"])

两者都给我一个指定的演员阵容无效。


有没有一种简单的方法可以做到这一点


isTrue = false

if((int)dbReader [" IsTrue" ] == 1)

isTrue = true;


谢谢,


Tom

>I have a value in my sql table set to tinyint (can''t set to bit).

I am trying to move it into a boolean field in my program and have tried:

isTrue = (int)dbReader["IsTrue"]

and

isTrue = Convert.ToBoolean((int)dbReader["IsTrue"])

Both give me a "Specified cast is not valid".

Is there a simple way to do this other then

isTrue = false
if ((int)dbReader["IsTrue"] == 1)
isTrue = true;

Thanks,

Tom





" Tom Dacon" < td **** @ community.nospamwrote in message

news:Oz ************** @ TK2MSFTNGP05.phx.gbl ...

"Tom Dacon" <td****@community.nospamwrote in message
news:Oz**************@TK2MSFTNGP05.phx.gbl...

如何


isTrue =(dbReader(" IsTrue")< 0
How about:

isTrue = (dbReader("IsTrue") <0



实际上,它会是这样的:


isTrue =(int)dbReader [" IsTrue"]!= 0;





isTrue =((int)dbReader [" IsTrue"])!= 0;

但是我得到了同样的错误。


谢谢,


tom

Actually, it would be something like:

isTrue = (int)dbReader["IsTrue"] != 0;

or

isTrue = ((int)dbReader["IsTrue"]) != 0;

but I get the same error.

Thanks,

tom


>

Tom Dacon

Dacon软件咨询


" tshad"< ts *** @ dslextreme.com写信息

新闻:%2 **************** @ TK2MSFTNGP04.phx.gbl ...
>
Tom Dacon
Dacon Software Consulting

"tshad" <ts***@dslextreme.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...

>>我的sql表中的值设置为tinyint(不能设置为位)。

我试图将其移动到我的程序中的布尔字段并且有试过:

isTrue =(int)dbReader [" IsTrue"]


isTrue = Convert.ToBoolean((int)dbReader [ IsTrue])

两者都给我一个指定的演员阵容无效。

有没有一种简单的方法可以做到这一点

isTrue = false
if((int)dbReader [" IsTrue"] == 1)
isTrue = true;

谢谢,

>>I have a value in my sql table set to tinyint (can''t set to bit).

I am trying to move it into a boolean field in my program and have tried:

isTrue = (int)dbReader["IsTrue"]

and

isTrue = Convert.ToBoolean((int)dbReader["IsTrue"])

Both give me a "Specified cast is not valid".

Is there a simple way to do this other then

isTrue = false
if ((int)dbReader["IsTrue"] == 1)
isTrue = true;

Thanks,

Tom




这篇关于将tinyint转换为布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆