Question : Type of conditional expression cannot be determined because there is no implicit

I have no idea what this error message is trying to tell me.  Can someone clue me into what this means?
Code Snippet:
1:
MyGlobalVars.docnpi = patient.d.NPI != null ? Convert.ToInt32(patient.d.NPI) : DBNull.Value;

Answer : Type of conditional expression cannot be determined because there is no implicit

Hi Kenny;

This is what I have found.

Fernando
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
//============= COMMENT =======================================
// This is the query that is used by the statement in question.
//=============================================================
var patients = from p in dceClinicalWorks.patients
               where p.Imported == null
               join d in dceClinicalWorks.doctors on p.doctorId equals d.doctorID
               join u in dceClinicalWorks.users on p.pid equals u.uid
               join i in dceClinicalWorks.patientinfos on p.pid equals i.pid
               select new { d, u, i, p };
 
//============= COMMENT =======================================
// This is the statement with the error 
//=============================================================
MyGlobalVars.docnpi = patient.d.NPI.GetValueOrDefault();
 
//============= COMMENT =======================================
// MyGlobalVars.docnpi is defined as an integer of nullable type
//
//        // Global Variables Class 
//        internal static class MyGlobalVars
//        {
//            public static int? docnpi;   //<======= int of nullable type
//            public static Guid initGuid;
//        }
//
// The variable patient.d.NPI which comes from the above query is of type String
// as shown in the following code snippet from the doctors table in the database.
// The code snippet comes from the file DataClasses2.designer.cs.
//
//		[Column(Storage="_NPI", DbType="VarChar(30) NOT NULL", CanBeNull=false)]
//		public string NPI
//		{
//			get
//			{
//				return this._NPI;
//			}
//			set
//			{
//				if ((this._NPI != value))
//				{
//					this.OnNPIChanging(value);
//					this.SendPropertyChanging();
//					this._NPI = value;
//					this.SendPropertyChanged("NPI");
//					this.OnNPIChanged();
//				}
//			}
//		}
//
// As you can see in the above snippet for NPI the database does NOT allow
// This column to be null, so NPI should always be returning a string value.
//
// In your original post you had this before we all had you change it.
//
// MyGlobalVars.docnpi = patient.d.NPI != null ? Convert.ToInt32(patient.d.NPI) : DBNull.Value;
//
// The String type or any reference type do not have a problem storing a null value and
// so no need to convert it to something else.
// 
// The issue is that you are attempting to place a string value that cannot be a null into
// a variable of type int. To correct the issue you need to decide what type of data NPI
// needs to be in the database, string or int, or change the MyGlobalVars.docnpi to be of type
// string to match the value being assigned by the database whcih will effect all MyGlobalVars.docnpi
// used to this point. Now if NPI is a string of numbers in the database then you can convert its
// value to an integer by doing the following:
//
// MyGlobalVars.docnpi = Convert.ToInt32(patient.d.NPI);
//=============================================================
Random Solutions  
 
programming4us programming4us