?
Solved

Pass Boolean to a store procedure

Posted on 2016-08-14
5
Medium Priority
?
56 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

801 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