Link to home
Start Free TrialLog in
Avatar of newjeep19
newjeep19Flag for United States of America

asked on

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

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
Avatar of bepsoccer1
bepsoccer1
Flag of United States of America image

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

Avatar of newjeep19

ASKER

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

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.
servicesupportrep is a lookup. Basically, when the checkbox is checked. Then the name in the lookup field is inserted into a ssrs report.
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?
I tried somthing like this but still get the same error:

 if (chkShowServiceSupportRep.Checked == true) { servicesupportrep.Value = true; } else { servicesupportrep.Value = false; }
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
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?
If checkbox is check then insert name associated with the GUID in the lookup should be inserted into the report?
Correct?

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

            }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of bepsoccer1
bepsoccer1
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial