Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. VB and an SqlDataSource

VB and an SqlDataSource

Scheduled Pinned Locked Moved The Weird and The Wonderful
question
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Steve Wellens
    wrote on last edited by
    #1

    Why did the hair on the back of my neck stand up when I looked at this?

    Dim IsPresCheck As CheckBox = CType(FormView1.FindControl("IsPrestigeChkBx"), CheckBox)

    If IsPresCheck.Checked = "True" Then
    SqlDataSource1.SelectParameters.Add("IsPrestige", System.TypeCode.Int32, 1.ToString)
    Else
    SqlDataSource1.SelectParameters.Add("IsPrestige", System.TypeCode.Int32, 0.ToString)
    End If

    Steve Wellens

    P A B T 4 Replies Last reply
    0
    • S Steve Wellens

      Why did the hair on the back of my neck stand up when I looked at this?

      Dim IsPresCheck As CheckBox = CType(FormView1.FindControl("IsPrestigeChkBx"), CheckBox)

      If IsPresCheck.Checked = "True" Then
      SqlDataSource1.SelectParameters.Add("IsPrestige", System.TypeCode.Int32, 1.ToString)
      Else
      SqlDataSource1.SelectParameters.Add("IsPrestige", System.TypeCode.Int32, 0.ToString)
      End If

      Steve Wellens

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Do you have stringy hair?

      1 Reply Last reply
      0
      • S Steve Wellens

        Why did the hair on the back of my neck stand up when I looked at this?

        Dim IsPresCheck As CheckBox = CType(FormView1.FindControl("IsPrestigeChkBx"), CheckBox)

        If IsPresCheck.Checked = "True" Then
        SqlDataSource1.SelectParameters.Add("IsPrestige", System.TypeCode.Int32, 1.ToString)
        Else
        SqlDataSource1.SelectParameters.Add("IsPrestige", System.TypeCode.Int32, 0.ToString)
        End If

        Steve Wellens

        A Offline
        A Offline
        Andrew Rissing
        wrote on last edited by
        #3

        Because they couldn't take it sitting down! *rim shot*

        1 Reply Last reply
        0
        • S Steve Wellens

          Why did the hair on the back of my neck stand up when I looked at this?

          Dim IsPresCheck As CheckBox = CType(FormView1.FindControl("IsPrestigeChkBx"), CheckBox)

          If IsPresCheck.Checked = "True" Then
          SqlDataSource1.SelectParameters.Add("IsPrestige", System.TypeCode.Int32, 1.ToString)
          Else
          SqlDataSource1.SelectParameters.Add("IsPrestige", System.TypeCode.Int32, 0.ToString)
          End If

          Steve Wellens

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4

          That reminds me of a coding horror I experienced long ago. The value of an option was set on the server side, and that should determine if a checkbox on the client side was already checked or not. It worked well on all development computers, only on one terminal server - which was used for testing - that failed. I checked if the value was translated correctly from server to client ("false" was always a 0, but "true" was usually -1, sometimes +1, and rarely something else) - I got the correct bool value. I drilled further down the code and eventually stumbled over a great function (I am not sure if I reproduce that correctly, as I wrote vb code only several years ago):

          Sub ApplyOptionValue(Value as String)
          Value = Uppercase(Value)
          If Value = "WAHR" Then
          checkBox1.Checked = 1
          Else If Value = "FALSCH" Then
          checkBox1.Checked = 0
          Else
          checkBox1.Checked = 0
          End If

          When you pass a bool to a function which expects a string, VB just translates that bool to a string. On our development machines, we had the German version of Visual Studio, so a "True" was translated to "Wahr", but on the test machine, the relevant dll was in US English version, and hence the true value was "True", not "Wahr". Also note that the original programmer already considered such a case where the value was neither true nor false...

          S 1 Reply Last reply
          0
          • B Bernhard Hiller

            That reminds me of a coding horror I experienced long ago. The value of an option was set on the server side, and that should determine if a checkbox on the client side was already checked or not. It worked well on all development computers, only on one terminal server - which was used for testing - that failed. I checked if the value was translated correctly from server to client ("false" was always a 0, but "true" was usually -1, sometimes +1, and rarely something else) - I got the correct bool value. I drilled further down the code and eventually stumbled over a great function (I am not sure if I reproduce that correctly, as I wrote vb code only several years ago):

            Sub ApplyOptionValue(Value as String)
            Value = Uppercase(Value)
            If Value = "WAHR" Then
            checkBox1.Checked = 1
            Else If Value = "FALSCH" Then
            checkBox1.Checked = 0
            Else
            checkBox1.Checked = 0
            End If

            When you pass a bool to a function which expects a string, VB just translates that bool to a string. On our development machines, we had the German version of Visual Studio, so a "True" was translated to "Wahr", but on the test machine, the relevant dll was in US English version, and hence the true value was "True", not "Wahr". Also note that the original programmer already considered such a case where the value was neither true nor false...

            S Offline
            S Offline
            supercat9
            wrote on last edited by
            #5

            Who came up with the notion that implicit conversions should be anything other than culture-invariant? That's a "coding horror" right there, IMHO.

            1 Reply Last reply
            0
            • S Steve Wellens

              Why did the hair on the back of my neck stand up when I looked at this?

              Dim IsPresCheck As CheckBox = CType(FormView1.FindControl("IsPrestigeChkBx"), CheckBox)

              If IsPresCheck.Checked = "True" Then
              SqlDataSource1.SelectParameters.Add("IsPrestige", System.TypeCode.Int32, 1.ToString)
              Else
              SqlDataSource1.SelectParameters.Add("IsPrestige", System.TypeCode.Int32, 0.ToString)
              End If

              Steve Wellens

              T Offline
              T Offline
              The Manoj Kumar
              wrote on last edited by
              #6

              You can use GEL to hold your hairs :)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups