I’m trying to find the Exception ex message for why my Table Update is failing. But I can only see the result 0 and Record Failed to update.
Here is my code :
public int UpdatePatient(Patient patient)
{
int result = 0;
try
{
result = _db.Update(patient);
if (result == 0)
{
// Show error message
Debug.WriteLine("Failed to update patient.");
//return -1;
}
else
{
//return result;
}
}
catch (Exception ex)
{
// Show error message
Debug.WriteLine("An error occurred while updating the patient: " + ex.Message);
//return -1;
}
return result;
}
And it is called using the following:
PatientRepository pr = new PatientRepository();
int success = pr.UpdatePatient(patient);
How can I capture the Exception message that will tell me “why” it is failing?