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