1.11M Members

How to check value of boolean variable ?

 
0
 

Dear Friends,

I am developing an application for multi user using vb.net with back end as ms-access. For the table name as employee_master, there is a column, name as student_profile having datatype as Yes/No .

If value of student_profile is "yes" then label1 will be shown and

If value of student_profile is "No" then label2 will be shown

For this I use this code

Private Sub show_userid_employee_no()
        Dim dbConn As OleDbConnection
        Dim dbCommand As New OleDbCommand

                dbConn = New OleDbConnection(cnSettings())
        dbCommand.CommandText = "SELECT * FROM [Employee_master] Where User_id = '" & Login_Page.user_id.Text & "' And [password] = '" & Login_Page.password.Text & "'"

        dbCommand.Connection = dbConn
        dbConn.Open()
        Dim dbDR As OleDb.OleDbDataReader = dbCommand.ExecuteReader
        Try
            While dbDR.Read
               
                Dim label2 As New Label
                Dim label4 As New Label
                Dim label5 As New Label
                Me.Label2.Text = CStr(dbDR("user_id"))
                Me.Label4.Text = CStr(dbDR("employee_id"))



                Dim Student_profile As Boolean

                If Student_profile = True Then
                    MsgBox("HI vasim")
                Else
                    MsgBox("Who are you")
                End If      
      End While
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
        Finally
            dbConn.Close()
        End Try
    End Sub
 
0
 

You never get the value of Student_profile from the database. You also stated that the type of that column was Yes/No. My SQL is somewhat rusty but you later say you want to test against the values "yes" and "No". I don't think that a Yes/No field is actually stored as "Yes" or "No". Try

Student_profile = dbDR("student_profile")

and see where that gets you. If you get into the debugger you might try looking at the type of that column as it is returned from dbDR. If it returns a boolean then your If statement will be

If Student_profile then
    MsgBox("HI vasim"
.
.
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article