14 Replies - 448 Views - Last Post: 05 July 2013 - 09:03 PM Rate Topic: -----

#1 johnedcel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 01-July 13

how to convert boolean into string?

Posted 05 July 2013 - 07:43 PM

Can someone help me on how to convert or to get the value of boolean into string?

i have a field in my database sex and has a boolean data type.
0 = male
1 = female

i have a textbox and i need to type there the gender of the user. how can i do this? TIA.
Is This A Good Question/Topic? 0
  • +

Replies To: how to convert boolean into string?

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8955
  • View blog
  • Posts: 33,571
  • Joined: 12-June 08

Re: how to convert boolean into string?

Posted 05 July 2013 - 07:48 PM

You can do it in your select statement... if it's normal sql then use a 'case-when' and have it output the string type.
Was This Post Helpful? 0
  • +
  • -

#3 johnedcel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 01-July 13

Re: how to convert boolean into string?

Posted 05 July 2013 - 07:51 PM

could you give an example? by the way i am using c# and crm 2011. i have a class that looks like this
public Beneficiary PushHHID(string Firstname, string Middlename,string Lastname, Boolean Sex)
and i'm also using query expressions like
query.Criteria.AddCondition("new_age", ConditionOperator.Equal, Sex);
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8955
  • View blog
  • Posts: 33,571
  • Joined: 12-June 08

Re: how to convert boolean into string?

Posted 05 July 2013 - 07:57 PM

Where's your SELECT statement?
Was This Post Helpful? 0
  • +
  • -

#5 johnedcel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 01-July 13

Re: how to convert boolean into string?

Posted 05 July 2013 - 08:05 PM

you can't use SELECT statement in CRM. the equivalent of SELECT statement in CRM is something like this
QueryExpression query = new QueryExpression
{
EntityName = "contact",
ColumnSet = new ColumnSet("new_householdid", "firstname", "middlename", "lastname", "new_age", "new_sex", "new_birthday")

};
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8955
  • View blog
  • Posts: 33,571
  • Joined: 12-June 08

Re: how to convert boolean into string?

Posted 05 July 2013 - 08:13 PM

... so by that sound you are _not_ using a SELECT statement? Okay then take the long way around - when you get your data back, and before you shove it into a textfield, just check to see the value and use an if statement to convert it to text.
Was This Post Helpful? 0
  • +
  • -

#7 johnedcel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 01-July 13

Re: how to convert boolean into string?

Posted 05 July 2013 - 08:14 PM

this is how i pass the values
bool sex = false;
 sex = Convert.ToBoolean(x.Attributes["new_sex"]);
                            if (sex == false)
                            {
                                beneinfo.Sex = "male";
                            }
                            else {
                                beneinfo.Sex = "female";
                            }

This post has been edited by modi123_1: 05 July 2013 - 08:16 PM
Reason for edit:: please use code tags

Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8955
  • View blog
  • Posts: 33,571
  • Joined: 12-June 08

Re: how to convert boolean into string?

Posted 05 July 2013 - 08:16 PM

Okay - I am not sure how I should respond to that.
Was This Post Helpful? 0
  • +
  • -

#9 johnedcel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 01-July 13

Re: how to convert boolean into string?

Posted 05 July 2013 - 08:26 PM

public Beneficiary PushHHID(string Firstname, string Middlename,string Lastname, string Sex)
        {
            try
            {

                //Authenticate using credentials of the logged in user;
                // ClientCredentials Credentials = new ClientCredentials();
                ClientCredentials Credentials = new ClientCredentials();
                Credentials.UserName.UserName = "username";
                Credentials.UserName.Password = "password";


                //This URL needs to be updated to match the servername and Organization for the environment.
                //Uri OrganizationUri = new Uri(String.Format("htp://escms-crm/eSCMS/XRMServices/2011/Organization.svc"));
                Uri OrganizationUri = new Uri("http://escms-crm/eSCMS/XRMServices/2011/Organization.svc");
                Uri HomeRealmUri = null;

                //Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

                //OrganizationServiceProxy serviceProxy;


                //DateTime bday = contact.new_Birthday.Value;
                //int aage = contact.new_Age.Value;


                using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))
                {

                    IOrganizationService service = (IOrganizationService)serviceProxy;


                    QueryExpression query = new QueryExpression
                    {
                        EntityName = "contact",
                        ColumnSet = new ColumnSet("new_householdid", "firstname", "middlename", "lastname", "new_age", "new_sex", "new_birthday")

                    };


                    query.Criteria.AddCondition("firstname", ConditionOperator.Equal, Firstname);
                    query.Criteria.AddCondition("middlename", ConditionOperator.Equal, Middlename);
                    query.Criteria.AddCondition("lastname", ConditionOperator.Equal, Lastname);
                    query.Criteria.AddCondition("new_age", ConditionOperator.Equal, Sex);
                    //query.Criteria.AddCondition("new_birthday", ConditionOperator.Equal, Birthday.ToString()); 
                    


                    EntityCollection result1 = service.RetrieveMultiple(query);


                   Beneficiary beneinfo = new Beneficiary();

                        bool sex = false;
                

                        foreach (var x in result1.Entities)
                        {
                            beneinfo.HouseholdId = x.Attributes["new_householdid"].ToString();
                            beneinfo.Firstname = x.Attributes["firstname"].ToString();
                            beneinfo.Age = Convert.ToInt32(x.Attributes["new_age"]);
                            beneinfo.Middlename = x.Attributes["middlename"].ToString();
                            beneinfo.Lastname = x.Attributes["lastname"].ToString();
                            
                            sex = Convert.ToBoolean(x.Attributes["new_sex"]);
                            if (sex == false)
                            {
                                beneinfo.Sex = "male";
                            }
                            else {
                                beneinfo.Sex = "female";
                            }



here is my whole code.
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8955
  • View blog
  • Posts: 33,571
  • Joined: 12-June 08

Re: how to convert boolean into string?

Posted 05 July 2013 - 08:29 PM

Okay dokey.. so yeah.. there you go.. if statements for the win.
Was This Post Helpful? 0
  • +
  • -

#11 johnedcel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 01-July 13

Re: how to convert boolean into string?

Posted 05 July 2013 - 08:34 PM

where should i put the if statement? after the query? and if so what is the syntax? im sorry i am really a newbie and im just trying to debug this code.
Was This Post Helpful? 0
  • +
  • -

#12 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8955
  • View blog
  • Posts: 33,571
  • Joined: 12-June 08

Re: how to convert boolean into string?

Posted 05 July 2013 - 08:37 PM

What's the issue with it running there? Assuming class "Beneficiary"'s property "Sex" is a string, it would make sense.
Was This Post Helpful? 0
  • +
  • -

#13 johnedcel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 01-July 13

Re: how to convert boolean into string?

Posted 05 July 2013 - 08:43 PM

yes but in the database the data type of Sex is boolean. 0 = male 1 = female
Was This Post Helpful? 0
  • +
  • -

#14 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8955
  • View blog
  • Posts: 33,571
  • Joined: 12-June 08

Re: how to convert boolean into string?

Posted 05 July 2013 - 08:45 PM

yeah.. that's the whole point of the 'if' statement. It says 'oh - hai boolean value I see.. when I see this type of boolean I'll just tell the property of class 'Beneficiary' that I mean this <insert string value> string value!".
Was This Post Helpful? 0
  • +
  • -

#15 johnedcel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 01-July 13

Re: how to convert boolean into string?

Posted 05 July 2013 - 09:03 PM

thanks a lot. actually i think my real problem is that
query.Criteria.AddCondition("new_age", ConditionOperator.Equal, Sex);
the condition is wrong. instead of sex the condition i place is age hahaha.

thanks a lot! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1