• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1537
  • Last Modified:

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?
MyGlobalVars.docnpi = patient.d.NPI != null ? Convert.ToInt32(patient.d.NPI) : DBNull.Value;

Open in new window

0
kwh3856
Asked:
kwh3856
  • 3
  • 3
  • 2
1 Solution
 
PlatoConsultantCommented:
try
MyGlobalVars.docnpi = patient.d.NPI != null ? Convert.ToInt32(patient.d.NPI) : DBNull.Value;

catch ex as exception
   messagebox.show(ex.message)
end

it will give you exact exception
0
 
PlatoConsultantCommented:
Visual Basic Language Reference
IsDBNull Function

Returns a Boolean value indicating whether an expression evaluates to the System.DBNull class.


Dim testVar As Object
Dim nullCheck As Boolean
nullCheck = IsDBNull(testVar)
testVar = ""
nullCheck = IsDBNull(testVar)
testVar = System.DBNull.Value
nullCheck = IsDBNull(testVar)
' The first two calls to IsDBNull return False; the third returns True.

Open in new window

0
 
kwh3856Author Commented:
Plato,
I tried that and got this error

Type of conditional expression cannot be determined because there is no implicit conversion between 'int' and 'System.DBNull'    

Thanks
Kenny

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Fernando SotoCommented:
Hi Kenny;

try this change this line of code in the MyGlobalVars class:

public static int docnpi;

to this:

public static int? docnpi;


Change this line at the end of the code:

MyGlobalVars.docnpi = patient.d.NPI != null ? (int)myMPI.NPI : 0;

To this:

MyGlobalVars.docnpi = patient.d.NPI.GetValueOrDefault();

Fernando
0
 
kwh3856Author Commented:
Fernando,
When I tried that I got
'string' does not contain a definition for 'GetValueOrDefault' and no extension method 'GetValueOrDefault' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
 
Thanks
Kenny
 
0
 
Fernando SotoCommented:
Hi Kenny;

This is what I have found.

Fernando
//============= 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);
//=============================================================

Open in new window

0
 
kwh3856Author Commented:
Fernando,
Thank you for such a verbose explanation.  I realize now I need to define it as a string and then do the conversion when I save it.

Thanks
Kenny
0
 
Fernando SotoCommented:
Not a problem, always glad to help out.  ;=)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now