从DataTable中获取布尔值
如何检索数据集中的布尔值,我正在使用 Visual Studio 2003,我正在尝试以下操作,但它不起作用:
//if product inactive, don't display, and redirect to main page
if((dbDataSet.Tables["productGeneral"].Rows[0]["Active"].Equals(0)))
我什至尝试过,但不起作用:
if((dbDataSet.Tables["productGeneral"].Rows[0]["Active"].toString() == false)
列名称是 [“active”],值与列中的值为 True 或 False,使用 sql server 2000
请帮忙
How do I retrieve a Boolean value in dataset, I'm using visual studio 2003,I am trying the following, but it's not working:
//if product inactive, don't display, and redirect to main page
if((dbDataSet.Tables["productGeneral"].Rows[0]["Active"].Equals(0)))
I even tried, but not working:
if((dbDataSet.Tables["productGeneral"].Rows[0]["Active"].toString() == false)
the columns name is ["active"], the value with in column is either True or False, using sql server 2000
please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要直接转换为布尔值,然后使用它进行检查。
你尝试过吗?:
如果它是布尔值,你会想直接将结果转换为布尔值。
第一个失败,因为 0 是 Int32,而不是布尔值。 它们在 C# 中不具有可比性,因为它们是不同的类型。 第二个失败,因为 ToString() 将结果转换为字符串,并且您将字符串与布尔值进行比较,这又不起作用。
You need to cast to a bool directly, and just check using that.
Have you tried?:
If it's a bool, you'll want to cast the result to a bool directly.
The first fails since 0 is an Int32, not a Boolean. They are not comparable in C#, since they're distinct types. The second fails since ToString() turns the result into a string, and you're comparing a string to a bool, which again will not work.
尝试以下方法
Try out the following