Link to home
Start Free TrialLog in
Avatar of kwh3856
kwh3856Flag for United States of America

asked on

Cannot implicitly convert type 'int?' to 'int'. An explicit conversion exists (are you missing a cast?)

I am not sure I understand this error message.  If two variable are already defined as integer why am I getting this error message.  I am not sure what it means.  Any help is greatly appreciated.

Here is my code where I get it.


// Global Variables Class 
        internal static class MyGlobalVars 
        {
            public static int docnpi;
            public static Guid initGuid;
        }
 
 
 
 
 
................down in the middle of my code I have................................
 myMPI.NPI = Convert.ToInt32(patient.d.NPI);
                MyGlobalVars.docnpi = myMPI.NPI;--------squiggly under the myMPI.NPI

Open in new window

Avatar of p_davis
p_davis

myMPI.NPI = Convert.ToInt32(patient.d.NPI.Value);


not sure that you need the conversion though

you might want to do this

if(patient.d.NPI.HasValue)
  myMPI.NPI = patient.d.NPI.Value;
ASKER CERTIFIED SOLUTION
Avatar of naspinski
naspinski
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
Will probably work if you add (int) in front of it (including brackets).
Ah, forget my comment, I didn't read well. Naspinski has better eyes here ;)
a little cleaner:
MyGlobalVars.docnpi = myMPI.NPI.GetValueOrDefault();

Open in new window

Avatar of kwh3856

ASKER

naspinski,
Thank you.  Your code worked just by pasting it in.  To each of you who chimed in, thank you.  Naspinski seemed to have the best solution for what I needed at this time.  Once again, thank you.