强制Checkbox返回整数而不是布尔值 [英] Forcing Checkbox to Return integer instead of boolean

查看:81
本文介绍了强制Checkbox返回整数而不是布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




使用V Web 2005:

我在页面上有复选框。如果未选中该框,我想存储0或者如果存在则存储1(作为整数 - 因为sql表

最终将被其他无法处理布尔值的软件使用)。 br />
" CBAnswer1.Checked.tostring"给我真实或假这样就不行了。下面的代码可以做我想要它做的事情(使用函数对SQL表进行实际更新) - 但是必须有更多的直接来自
直接初始化复选框的方法,以便返回整数1而不是布尔值true的东西。如果检查了

(因为我必须多次这样做)。


Dim A1 As Integer = 0

如果CBAnswer1.Checked然后

A1 = 1:结束如果

ReadAndStoreIntAnswer(A1," XXX")


有什么想法吗?


提前致谢


Jeff


-

通过 http://www.teranews.com 上的免费Usenet帐户发布



Using V Web 2005:
I have checkbox on a page. I want to store either 0 if the box is not checked or 1 if it is (as integers - because the sql table
will ultimately be used by other software that can''t handle booleans ).
"CBAnswer1.Checked.tostring" gives me "True" or "False" so that won''t work. The code below works to do what I
want it to do (using a function to do the actual update to an SQL table) - but there must be a more
direct method to initialize the checkbox so that something that returns an integer 1 instead of the boolean "true" if it is checked
(as I have to do this multiple times).

Dim A1 As Integer = 0
If CBAnswer1.Checked Then
A1 = 1 : End If
ReadAndStoreIntAnswer(A1, "XXX")

Any ideas?

Thanks in advance

Jeff

--
Posted via a free Usenet account from http://www.teranews.com

推荐答案

为什么不用math.abs(cint(checkbox1.checked))?


" Jeff" ; < no ** @non.comwrote in message

news:45 *********************** @ free.teranews。 com ..
Why not math.abs(cint(checkbox1.checked)) ?

"Jeff" <no**@none.comwrote in message
news:45***********************@free.teranews.com.. .

>


使用V Web 2005:

我在页面上有复选框。如果盒子不是
,我想存储0或者如果它是1则存储(因为整数 - 因为sql表

最终会被其他可以使用的软件使用不处理布尔值。

" CBAnswer1.Checked.tostring"给我真实或假这样就不会工作了。下面的代码可以做我想要它做的事情(使用函数对SQL表进行实际更新) -

但是必须有更多

用于初始化复选框的直接方法,以便返回

整数1而不是布尔值true的东西。如果检查了

(因为我必须多次这样做)。


Dim A1 As Integer = 0

如果CBAnswer1.Checked然后

A1 = 1:结束如果

ReadAndStoreIntAnswer(A1," XXX")


有什么想法吗?


提前致谢


Jeff


-

通过 http://www.teranews.com 上的免费Usenet帐户发布
>

Using V Web 2005:
I have checkbox on a page. I want to store either 0 if the box is not
checked or 1 if it is (as integers - because the sql table
will ultimately be used by other software that can''t handle booleans ).
"CBAnswer1.Checked.tostring" gives me "True" or "False" so that won''t
work. The code below works to do what I
want it to do (using a function to do the actual update to an SQL table) -
but there must be a more
direct method to initialize the checkbox so that something that returns an
integer 1 instead of the boolean "true" if it is checked
(as I have to do this multiple times).

Dim A1 As Integer = 0
If CBAnswer1.Checked Then
A1 = 1 : End If
ReadAndStoreIntAnswer(A1, "XXX")

Any ideas?

Thanks in advance

Jeff

--
Posted via a free Usenet account from http://www.teranews.com



如果你想要一个整数,就不需要转换为字符串。

如果你想要一只烤鸡,你会买冰淇淋吗?

当然不是。只需转换为您需要的类型,如下所示:


Dim A1 as integer = Convert.ToInt32(CBAnswer1.Checked)

ReadAndStoreIntAnswer(A1," ; XXX")

No need to convert to string if you want an integer.
Would you buy icecream if you wanted a roast chicken?
Of course not. Just convert to the types that you need, as below:

Dim A1 as integer = Convert.ToInt32(CBAnswer1.Checked)
ReadAndStoreIntAnswer(A1, "XXX")


Hello Jeff,


完全不需要任何转换。只需告诉您的

SQL表,该字段的数据类型为BIT。然后你可以传递一个BOOLEAN

作为参数,一切都很好。它在数据库中为0或1,在.NET中为True

或False。简单。


-Boo
Hello Jeff,

There is no need at all for any conversion of any kind. Simply tell your
SQL table that this field has a data type of BIT. Then you can pass a BOOLEAN
as the parameter and all is well. It''s a 0 or 1 in the database and a True
or False in .NET. Simplicity.

-Boo

使用V Web 2005:


我在页面上有复选框。如果盒子不是
,我想存储0或者如果是,则存储1(作为整数 - 因为sql表


最终将由其他无法处理布尔值的软件

)。


" CBAnswer1.Checked.tostring"给我真实或假这样就不会工作了。下面的代码可以做我想要它做的事情(用一个函数来实际更新到一个SQL

表) - 但必须更多


直接方法来初始化复选框,以便

返回一个整数1而不是布尔值true如果检查了


(因为我必须多次这样做)。


Dim A1 As Integer = 0

如果CBAnswer1.Checked那么

A1 = 1:结束如果

ReadAndStoreIntAnswer(A1," XXX")

有什么想法吗?


提前致谢


Jeff
Using V Web 2005:

I have checkbox on a page. I want to store either 0 if the box is not
checked or 1 if it is (as integers - because the sql table

will ultimately be used by other software that can''t handle booleans
).

"CBAnswer1.Checked.tostring" gives me "True" or "False" so that won''t
work. The code below works to do what I

want it to do (using a function to do the actual update to an SQL
table) - but there must be a more

direct method to initialize the checkbox so that something that
returns an integer 1 instead of the boolean "true" if it is checked

(as I have to do this multiple times).

Dim A1 As Integer = 0
If CBAnswer1.Checked Then
A1 = 1 : End If
ReadAndStoreIntAnswer(A1, "XXX")
Any ideas?

Thanks in advance

Jeff



这篇关于强制Checkbox返回整数而不是布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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