Cannot implicitly convert type 'string' to 'char?

Posted on 2009-02-07
Medium Priority
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

Question by:kwh3856
LVL 11

Expert Comment

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.



Author Comment

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

Accepted Solution

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

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

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


to convert the char to a string
LVL 18

Assisted Solution

DropZone earned 1000 total points
ID: 23583693

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
        // 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:
   // etc.

Each method is overloaded to accept most data types.  Here's more information on these methods:

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:
And to convert a DateTime value to a string, use:

     I hope this helps.

Author Closing Comment

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

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.
LVL 18

Expert Comment

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.


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