Solved

Pass Boolean to a store procedure

Posted on 2016-08-14
5
38 Views
Last Modified: 2016-08-17
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
Comment
Question by:mcrmg
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:Steve Groner
ID: 41755607
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
 

Author Comment

by:mcrmg
ID: 41755608
thanks for the quick reply. Would it work if the user did not select neither YES nor NO?  thanks
0
 
LVL 1

Accepted Solution

by:
Steve Groner earned 500 total points
ID: 41755624
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
 

Author Comment

by:mcrmg
ID: 41755637
thank you
0
 

Author Closing Comment

by:mcrmg
ID: 41759208
thank you
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now