How do I retrieve boolean data from 1 column of a table in my database?

Posted on 2012-09-11
Last Modified: 2012-09-13
In my app., I have an order form that when the order is completed, the user checks a "Completed" checkbox (boolean data). When this checkbox is checked it removes the order form the open orders list (& does other functions). On this form I have a label that I would like to be visible only when there are open orders. I have tried a datareader & a dataset to try to get this boolean data but I am unable to retrieve just this 1 column's data from the data table.

Dim Con as new Odbc,OdbcConnection
Dim Com as new Odbc.OdbcCommand
Com.CommandText = ("Select Completed from Orders")
Com.Connection = Con

I believe I have to do a loop thru the rows to get this data. I don't need to put it into any kind of lable or textbox. I just want to be able to read the boolean data so that if there is just 1 open order the open order label will be visible.

Question by:grouchyfd
    LVL 26

    Expert Comment

    by:Alan Warren
    You should be able to set the visible property of the label evaluate the value of the sql field 'Completed'.
    <asp:Label Visible='<%# Eval("Completed") %>' ... />

    Open in new window

    Or maybe even better, modify your SQL to return a value to be used specifically by the labels visible property.

    We would have to invert the value of Completed, so if the checkbox is checked, return 0(false) for the calculated field LabelVisible, else return 1(true), we can use a JET Immediate If to do that.
    SELECT Orders.*, IIf([Completed]=0,1,0) AS LabelVisible FROM Orders;
    <asp:Label Visible='<%# Eval("Completed") %>' ... />

    Open in new window


    Author Comment

    Being a windows app (client/server) I'm not real fluent in I'm using visual So what your saying I might be able to have the visible property of the label be able to evaluate the true(1)/false(0) data from the column of the database?
    LVL 26

    Expert Comment

    by:Alan Warren
    Hi grouchyfd,

    Apologies for the ASP .Net response, didn't even realise I had switched topic areas.

    How do you navigate your VB .Net form records?

    If you use a BindingNavigator you could set the visible property of the Label using the RefreshItems Event.

    Private Sub BindingNavigator1_RefreshItems(sender As System.Object, e As System.EventArgs) Handles BindingNavigator1.RefreshItems
            Me.Label1.Visible = Not Me.CheckBox1.Checked
    End Sub

    Open in new window

    LVL 83

    Accepted Solution

    >On this form I have a label that I would like to be visible only when there are open orders.

    Try following

    Dim dbcon As New OdbcConnection("connection string")
    Dim dbcmd As New OdbcCommand("Select Count(*) From Orders Where Completed = 0", dbcon)

    Dim count as Integer = dbcmd.ExecuteScalar()

    if Count > 0 Then
       MyLabel.Visible = true
       MyLabel.Visible = false
    End If

    Author Comment

    I apologize for the delay. Unfortunately using the checked state of the checkbox only works for an individual record of the form. The logic of filtering the data (from the database) where completed = false and getting that row count works fine becuase it will only retrieve the rows that indicate that they haven't been completed yet. Thank you for helping me with the logic of this.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now