[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 427
  • Last Modified:

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

In my ADO.net 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
Con.Open()

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.

Thanks
0
grouchyfd
Asked:
grouchyfd
  • 2
  • 2
1 Solution
 
Alan WarrenCommented:
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

Alan
0
 
grouchyfdAuthor Commented:
Being a windows app (client/server) I'm not real fluent in asp.net. I'm using visual basic.net. 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?
0
 
Alan WarrenCommented:
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

Alan
0
 
CodeCruiserCommented:
>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)
dbcon.Open

Dim count as Integer = dbcmd.ExecuteScalar()
dbcmd.Dispose()
dbcon.Dispose()

if Count > 0 Then
   MyLabel.Visible = true
Else
   MyLabel.Visible = false
End If
0
 
grouchyfdAuthor Commented:
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.
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now