Solved

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

Posted on 2013-05-10
11
447 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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
 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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 shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
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…

776 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