Solved

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

Posted on 2013-05-10
11
445 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
DevOps Toolchain Recommendations

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

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

23 Experts available now in Live!

Get 1:1 Help Now