Cannot implicitly convert type 'string' to 'char?

Posted on 2009-02-07
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 =;------Squiggly line under

Open in new window

Question by:kwh3856
    LVL 11

    Expert Comment

    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 ?

    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

    myCRpatient.Sex is a VARCHAR(1) in the database is a nvarchar
    LVL 23

    Accepted Solution

    The .Net types would be more helpful than the database types.

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

    Open in new window

    LVL 15

    Expert Comment

    You should do one of the following

    Change the type of to a string

    or you might be able to use

    to convert the char to a string
    LVL 18

    Assisted Solution


    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

    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

    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

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    754 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

    20 Experts available now in Live!

    Get 1:1 Help Now