?
Solved

Cannot implicitly convert type 'string' to 'char?

Posted on 2009-02-07
7
Medium Priority
?
2,095 Views
Last Modified: 2013-12-16
I know this is simple for most of you out there but I do not know the coversion syntax it needs.  Can someone post up the syntax for this conversion.

myCRpatient.SEX = patient.u.sex;------Squiggly line under patient.u.sex

Open in new window

0
Comment
Question by:kwh3856
7 Comments
 
LVL 11

Expert Comment

by:rowansmith
ID: 23582545
It depends completely on what the types are defined as?

Is myCRpatuient.SEX a string? a Boolean?  a number? what is it?

And then what type is patient.u.sex ?

To set them you have to know what each one is, if you mouse over them the IDE will let you know what they are.

-Rowan

0
 

Author Comment

by:kwh3856
ID: 23582584
myCRpatient.Sex is a VARCHAR(1) in the database
patient.u.sex is a nvarchar
 
0
 
LVL 23

Accepted Solution

by:
Tony McCreath earned 1000 total points
ID: 23582726
The .Net types would be more helpful than the database types.

Maybe this will work:
myCRpatient.SEX = patient.u.sex[0];

Open in new window

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 15

Expert Comment

by:ChloesDad
ID: 23582813
You should do one of the following

Change the type of patient.u.sex to a string

or you might be able to use

patient.u.sex.tostring

to convert the char to a string
0
 
LVL 18

Assisted Solution

by:DropZone
DropZone earned 1000 total points
ID: 23583693
kwh3856,

I see that you have a few of these posts for multiple data type conversions.  Most (all?) data type classes and structures in .NET have a TryParse() method that accepts a string to convert and a variable on which to store the converted value.  The method returns true if parsing succeeded, or false if it failed.  For example:
    if (Int32.TryParse(myString, out myInt))
    {
        // Success! myInt now contains the numeric value of myString
    }
    else
    {
        // Failed! MyInt is not defined.
    }

The TryParse() method only converts from strings to other types.  For conversions between different types, you can use the Convert class.  It has methods to convert to multiple types, such as:
   Convert.ToString()
   Convert.ToInt32()
   Convert.ToByte()
   Convert.ToDate()
   Convert.ToDouble()
   // etc.

Each method is overloaded to accept most data types.  Here's more information on these methods:
    http://articles.techrepublic.com.com/5100-10878_11-5834604.html

And lastly, if you want to convert anything to a string, this is even easier! Every object has a ToString() method that "stringifies" its value.  For example, to convert an Integer to a string, use:
     myIntegerValue.ToString()
And to convert a DateTime value to a string, use:
     myDateTimeValue.ToString()

     I hope this helps.
     -dZ.
0
 

Author Closing Comment

by:kwh3856
ID: 31544180
Cholor's Dad,
I tried that and it did not work.  I tried tiggerito and it worked the first time.  

DropZone,
Thank you.  I am now using your logic in many different places in my code.  Thank you for turning on the lights and bringing clairity to my understanding of conversions.
0
 
LVL 18

Expert Comment

by:DropZone
ID: 23584432
No worries.  I always think it is better to explain the root cause of a problem and showing how to avoid it than to just give a code solution.  "Give a man a fish...", and all that.

    Cheers!
     -dZ.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
Suggested Courses
Course of the Month6 days, 16 hours left to enroll

592 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