9 Replies - 625 Views - Last Post: 28 January 2018 - 09:33 AM

#1 alobi   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 186
  • Joined: 21-January 13

Not conveting yes/no to true false,

Posted 26 January 2018 - 07:15 AM

I have a column in access table HasPermission, with datatype Yes/no. what I am looking to see with select query is true when the checkbox is checked and false when it is not checked but it is giving false whether checked or not. Are there other things I need to do to get True or false? I am using vb.net and access database
thanks
Is This A Good Question/Topic? 0
  • +

Replies To: Not conveting yes/no to true false,

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15439
  • View blog
  • Posts: 61,865
  • Joined: 12-June 08

Re: Not conveting yes/no to true false,

Posted 26 January 2018 - 07:37 AM

What's your query look like?
Was This Post Helpful? 0
  • +
  • -

#3 alobi   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 186
  • Joined: 21-January 13

Re: Not conveting yes/no to true false,

Posted 26 January 2018 - 08:19 AM

View Postmodi123_1, on 26 January 2018 - 07:37 AM, said:

What's your query look like?

when I put a brekpoint at permission = dr("Permission").ToString it returns false
 Str = "SELECT * FROM  Users WHERE [UserName] [email protected]"
        cmd = New OleDbCommand(Str, conn)
        cmd.Parameters.AddWithValue("@UserName", txtUserName.Text)
        ' Dim Password As String = cmd.ExecuteNonQuery
        Dim dr As OleDbDataReader = cmd.ExecuteReader
        While dr.Read
            userFound = True
            Title = dr("Title").ToString
            FirstName = dr("FirstName").ToString
            LastName = dr("SurName").ToString
            save_password = dr("HashPassword").ToString
            salt = dr("Salt").ToString
            permission = dr("Permission").ToString

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15439
  • View blog
  • Posts: 61,865
  • Joined: 12-June 08

Re: Not conveting yes/no to true false,

Posted 26 January 2018 - 08:21 AM

So "permission" is a boolean?

Then 'dr("Permission")' needs to have type conversion done right.

inline..
https://docs.microso...rsion-functions

.. or the system.convert namespace.
https://docs.microso...framework-4.7.1
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6829
  • View blog
  • Posts: 28,319
  • Joined: 12-December 12

Re: Not conveting yes/no to true false,

Posted 26 January 2018 - 10:01 AM

What happens if you drop the "ToString"?
Was This Post Helpful? 0
  • +
  • -

#6 alobi   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 186
  • Joined: 21-January 13

Re: Not conveting yes/no to true false,

Posted 26 January 2018 - 10:06 AM

Yes permission is a Boolean and I have shown it on the first line of code, and I changed the last line to account for converting Permission to Boolean datatype but I am still getting false at permission when I set a breakpoint and highlight permission.
Thanks for you time


 Dim permission As Boolean = False
        conn.Open()
        Str = "SELECT * FROM  Users WHERE [UserName] [email protected]"
        cmd = New OleDbCommand(Str, conn)
        cmd.Parameters.AddWithValue("@UserName", txtUserName.Text)
        ' Dim Password As String = cmd.ExecuteNonQuery
        Dim dr As OleDbDataReader = cmd.ExecuteReader
        While dr.Read
            userFound = True
            Title = dr("Title").ToString
            FirstName = dr("FirstName").ToString
            LastName = dr("SurName").ToString
            save_password = dr("HashPassword").ToString
            salt = dr("Salt").ToString
            permission = CBool(dr("Permission")) '.ToString

Was This Post Helpful? 0
  • +
  • -

#7 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15439
  • View blog
  • Posts: 61,865
  • Joined: 12-June 08

Re: Not conveting yes/no to true false,

Posted 26 January 2018 - 10:15 AM

15           permission = CBool(dr("Permission")) '.ToString

The point was to make it a boolean AND NOT A STRING.. so telling it to convert TO A STRING is self defeating.


----
^ dummy; I am.
Posted Image

This post has been edited by modi123_1: 26 January 2018 - 10:31 AM

Was This Post Helpful? 0
  • +
  • -

#8 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6829
  • View blog
  • Posts: 28,319
  • Joined: 12-December 12

Re: Not conveting yes/no to true false,

Posted 26 January 2018 - 10:25 AM

(The ToString is commented out.)
Was This Post Helpful? 0
  • +
  • -

#9 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15439
  • View blog
  • Posts: 61,865
  • Joined: 12-June 08

Re: Not conveting yes/no to true false,

Posted 26 January 2018 - 10:30 AM

Son of a b. I apologize.

I'll sign out for the day. :/
Was This Post Helpful? 0
  • +
  • -

#10 alobi   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 186
  • Joined: 21-January 13

Re: Not conveting yes/no to true false,

Posted 28 January 2018 - 09:33 AM

RESOLVED: I was setting the breakpoint too early and that is why I kept getting false no matter the value in column, my bad. Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1