Solved

How to a Bool to a System.GUID in C#

Posted on 2013-05-10
11
444 Views
Last Modified: 2013-05-14
I need to convert a boolean value to a Guid using C#.
I get the below error message:
Cannot implicitly convert type 'bool' to 'System.Guid'

My code that caulse the error:
servicesupportrep.Value = chkShowServiceSupportRep.Checked;

Open in new window


Please help
0
Comment
Question by:newjeep19
  • 6
  • 5
11 Comments
 
LVL 4

Expert Comment

by:bepsoccer1
ID: 39156717
what exactly are you trying to do that you are needing to convert bool (0|1) to GUID (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)?

Not knowing any more about your values here you could try something like:

servicesupportrep.Value = new Guid(chkShowServiceSupportRep.Checked.tostring());

Open in new window

0
 

Author Comment

by:newjeep19
ID: 39156807
Thank you for your reply. Below is the entire code:
private Lookup servicesupportrep = new Lookup();

////SET CHECKBOXES ON PAGE
  protected void Page_Load(object sender, EventArgs e)
        {
          chkShowServiceSupportRep.Checked = rpt_servicesupportrep.ToLower() == "true" ? true: ( rpt_servicesupportrep == "" ? false : true); 
        }
// FUNCTION saves the record 
        protected void saveReportSelections(string QuoteId)
        {
           servicesupportrep.Value = chkShowServiceSupportRep.Checked; // causing the error
         }

Open in new window

0
 
LVL 4

Expert Comment

by:bepsoccer1
ID: 39156833
So why is servicesupportrep.Value a GUID if you are trying to assign it as true or false?  GUID is Globaly Unique Identifier.  Are you saving this to a DB?  Should maybe change the data type for servicesupportrep or you are trying to set the wrong value.
0
 

Author Comment

by:newjeep19
ID: 39156893
servicesupportrep is a lookup. Basically, when the checkbox is checked. Then the name in the lookup field is inserted into a ssrs report.
0
 
LVL 4

Expert Comment

by:bepsoccer1
ID: 39156923
Sounds more like you are wanting to do an If chkShowServiceSupportRep.Checked = 'true' then .....(write servicesupportrep.Value where ever it is you are writing it to.) or something like servicesupportrep.Value = chkShowServiceSupportRep.value?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:newjeep19
ID: 39156941
I tried somthing like this but still get the same error:

 if (chkShowServiceSupportRep.Checked == true) { servicesupportrep.Value = true; } else { servicesupportrep.Value = false; }
0
 
LVL 4

Expert Comment

by:bepsoccer1
ID: 39156978
Then what ever servicessupportrep needs to be created as a boolean not a GUID.  Or you need to be setting a different field associated to the "servicesupportrep" record, which is a guid, like "enabled", which would be boolean.  Data would look like this in a table.

servicesupportrep      enabled      Name
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx      TRUE      Someone
yyyyyyyy-xxxx-xxxx-xxxx-xxxxxxxxxxxx      FALSE      SomeoneElse
0
 

Author Comment

by:newjeep19
ID: 39156990
OK I gotcha....so, I would need to get the Guid of the person whom is on the lookup field and then if there is a Guid (name) there then true else false....correct?
0
 
LVL 4

Expert Comment

by:bepsoccer1
ID: 39157011
If checkbox is check then insert name associated with the GUID in the lookup should be inserted into the report?
0
 

Author Comment

by:newjeep19
ID: 39157028
Correct?

if (chkShowServiceSupportRep.Checked == true)
            {
                LookupName(Guid)  =  servicesupportrep.Value;
            }
            else
            {

            }

Open in new window

0
 
LVL 4

Accepted Solution

by:
bepsoccer1 earned 500 total points
ID: 39157079
possibly servicesupportrep.Value = LookupName(Guid)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How Can I fix my MouseHover Event? 14 27
LINQ question 7 21
cs.Designer Issue 2 14
How to Get total minutes between two hours 4 26
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

19 Experts available now in Live!

Get 1:1 Help Now