473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Error: Cannot implicitly convert type 'string' to 'bool'

4
Expand|Select|Wrap|Line Numbers
  1. //declare variable
  2.  
  3. internal bool CheckBox11 = false; 
  4.  
  5.  
  6.   if (!string.IsNullOrEmpty(Reader["CheckBox11"].ToString()))
  7.                 {
  8.                     CheckBoxID = Reader["CheckBox11"].ToString();
  9.                 }
  10.                 else
  11.                 {
  12.                     CheckBoxID.Checked = false;
  13.                 }
I don't know why I'm getting the error :S I am fairly new at this.. this is Visual C#

Please help me anyway you can, it is urgent!
Jun 8 '11 #1
4 3403
GaryTexmo
1,501 Expert 1GB
I don't think you've posted enough code here for me to get an idea of what's going on. What is Reader? Can you post more complete source? Also, please indicate the line the error occurs on.

If it's the line that reads CheckBoxId = Reader["CheckBox11"].ToString(); and CheckBoxID then that might be your problem. You can't convert a string to a boolean like that. Try the Convert class. There's a ToBoolean method you can use, though I'd recommend putting it in a try/catch.
Jun 8 '11 #2
Asma P
4
SqlDataReader Reader = cmdContact.ExecuteReader();

The above definition is the definition for reader.. it reads SQL data, and the part underlined in red is Reader["CheckBox11"].ToString();

Before the Page_Load method I have declared an internal bool:
internal bool CheckBox11 = false;
Jun 8 '11 #3
Asma P
4
O
BranchList.Visible = true;
BranchList.Enabled = true;
BranchList.Text = ("An Error occured!<br />" + ex.Message.ToString());
BranchList.ToolTip = ("An Error occured!<br />" + ex.Message.ToString());
return;

^^ That is in my catch clause the if statement is in a try
Jun 8 '11 #4
Asma P
4
Its ok I figured it out.. I needed to cast the thing Conver.ToBoolean before the entire right hand side Thanks alo
Jun 8 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Terminal882003 | last post by:
Hi, Here I have a question about MSCommLib. I need to dynamically add activeX controls that requires run-time license for MSCommLib. The following is the actual code: AxMSCommLib.AxMSComm...
3
by: Anita C | last post by:
I have the foll. code to update the value of an attribute: xmlDocument.Load("abc.xml"); XmlAttribute xmlAttrib = xmlDocument.SelectSingleNode(root/web/theme/@desc); xmlAttrib.Value =...
6
by: juli | last post by:
I declared: public delegate void PaintEventHandler(object objSender,PaintEventArgs pea); and this.Paint+=new PaintEventHandler(MyPaintHandler); and the: static void MyPaintHandler(object...
2
by: Jeff | last post by:
I get the following error: Cannot implicitly convert type 'Factory.Stack.pArrayStack' to 'Factory.Stack.StackDefs.ImStack' at compile time. I thought perhaps there was a mismatch between the...
2
by: Patrick Olurotimi Ige | last post by:
When i convert:- this code from VB to C# Why do i get error "Cannot implicitly convert type 'object' to 'bool' VB --- If cmdcommand.Parameters("ReturnValue").Value = 1 Then lblStatus.Text =...
3
by: Patrick Olurotimi Ige | last post by:
compiling the code below i get the error:- Cannot implicitly convert type 'object'to 'System.Xml.XmlDocument' I'm getting the error on this line:- myXml.Document =...
6
by: eric.goforth | last post by:
What's wrong with this? if (bool)(UserIDs == ThisUserId) { return true; }
1
by: rmrao | last post by:
protected override void InitializeCulture() { string culture = ""; culture = Request.QueryString; if (culture = null) culture = "en-US"; ...
3
by: sappyjosh | last post by:
public void Update_Stock(Inseed Is) { if (con.State == ConnectionState.Open) { con.Close(); } try { ...
2
by: vadiraj hebbar | last post by:
public static double reversenumber(double i) { i = 1 * i; if (i < 0) return i.ToString() + "is reverse number"; else if...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.