• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 60
  • Last Modified:

Pass Boolean to a store procedure

hi,

I am trying to pass a value of boolean to a sp. I am getting an error

Failed to convert parameter value from a String to a Boolean.

On the aspx page, I have code as
                                <asp:ListItem value="">Select</asp:ListItem>
                                <asp:ListItem value="True">Yes</asp:ListItem>                         
                                  <asp:ListItem value="False">No</asp:ListItem>

on CS page, I have code as

SqlCom.Parameters.Add("@var", System.Data.SqlDbType.Bit).Value = var.Text.ToString();


The field is a bit data type. Any ideas?  thx

Failed to convert parameter value from a String to a Boolean.
0
mcrmg
Asked:
mcrmg
  • 3
  • 2
1 Solution
 
Steve GronerLead Systems EngineerCommented:
Bit fields are either 0 or 1 or null.  Change the value in your ASPX to 0 = false and 1 = true.  Thank should help out.
0
 
mcrmgAuthor Commented:
thanks for the quick reply. Would it work if the user did not select neither YES nor NO?  thanks
0
 
Steve GronerLead Systems EngineerCommented:
You would need to pass the null in that case.  Just make sure your bit field in SQL is capable of allowing nulls as an acceptable value and you should be good.
0
 
mcrmgAuthor Commented:
thank you
0
 
mcrmgAuthor Commented:
thank you
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now