从DataTable中获取布尔值

发布于 2024-07-25 09:18:45 字数 425 浏览 6 评论 0原文

如何检索数据集中的布尔值,我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奢华的一滴泪 2024-08-01 09:18:45

您需要直接转换为布尔值,然后使用它进行检查。

你尝试过吗?:

if(((bool)dbDataSet.Tables["productGeneral"].Rows[0]["Active"] == false))

如果它是布尔值,你会想直接将结果转换为布尔值。

第一个失败,因为 0 是 Int32,而不是布尔值。 它们在 C# 中不具有可比性,因为它们是不同的类型。 第二个失败,因为 ToString() 将结果转换为字符串,并且您将字符串与布尔值进行比较,这又不起作用。

You need to cast to a bool directly, and just check using that.

Have you tried?:

if(((bool)dbDataSet.Tables["productGeneral"].Rows[0]["Active"] == false))

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.

極樂鬼 2024-08-01 09:18:45

尝试以下方法

   if (Convert.ToBoolean(dbDataSet.Tables["productGeneral"].Rows[0]["Active"]) == true)
   {}

Try out the following

   if (Convert.ToBoolean(dbDataSet.Tables["productGeneral"].Rows[0]["Active"]) == true)
   {}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文