Results 1 to 15 of 15

Thread: Checkbox not working

Hybrid View

  1. #1
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Checkbox not working

    This is silly code:
    Code:
                        Select Case True
                            Case Det01 = "True"
                                ccb01DetOverride.Checked = True
                            Case Else
                                ccb01DetOverride.Checked = False
                        End Select
    That's not what a Select Case is for. That would properly be written as:
    Code:
    If Det01 = "True" Then
        ccb01DetOverride.Checked = True
    Else
        ccb01DetOverride.Checked = False
    End If
    or, even more simply:
    Code:
    ccb01DetOverride.Checked = (Det01 = "True")
    You can easily set a breakpoint on the appropriate line and check the value of Det01 right as it's being used. A possible reason that it may not work as expected is that there is actually a space at the end of the text. Of course, if you want to store Boolean values in SQL Server then you should be using the bit data type rather than nvarchar if at all possible, but there may be a valid reason that that is not possible.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Apr 2016
    Posts
    97

    Re: Checkbox not working

    Quote Originally Posted by jmcilhinney View Post
    You can easily set a breakpoint on the appropriate line and check the value of Det01 right as it's being used. A possible reason that it may not work as expected is that there is actually a space at the end of the text. Of course, if you want to store Boolean values in SQL Server then you should be using the bit data type rather than nvarchar if at all possible, but there may be a valid reason that that is not possible.
    If you read carefully above in my original comments, the Det01 was indeed bringing me back my expected result. There are no spaces or other anomolies that would have resulted in my case select reading wrong...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width