5

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

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Developer
  • 2,987
  • 10
  • 40
  • 51

2 Answers2

4

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.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
1

Try out the following

   if (Convert.ToBoolean(dbDataSet.Tables["productGeneral"].Rows[0]["Active"]) == true)
   {}
Patrick D'Souza
  • 3,491
  • 2
  • 22
  • 39
pedrofernandes
  • 16,354
  • 10
  • 36
  • 43