Solved

Pass Boolean to a store procedure

Posted on 2016-08-14
5
26 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:sgroner
Comment Utility
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
Comment Utility
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:
sgroner earned 500 total points
Comment Utility
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
Comment Utility
thank you
0
 

Author Closing Comment

by:mcrmg
Comment Utility
thank you
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

8 Experts available now in Live!

Get 1:1 Help Now