VB and an SqlDataSource
-
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 IfSteve 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 IfSteve Wellens
Do you have stringy hair?
-
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 IfSteve Wellens
Because they couldn't take it sitting down! *rim shot*
-
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 IfSteve Wellens
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 IfWhen 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...
-
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 IfWhen 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...
-
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 IfSteve Wellens
You can use GEL to hold your hairs :)