// Method used to populate ListBox public static string patientToString(PatientsTable patient, HospitalDBEntities dbcon) { List <TestsTable> tests = dbcon.TestsTables.ToList(); List <MedicationListTable> meds = dbcon.MedicationListTables.ToList(); List <AppointmentsTable> appointments = dbcon.AppointmentsTables.ToList(); String final = "Name: " + patient.FirstName + " " + patient.LastName + "\nEmail: " + patient.Email + "\nTests:"; foreach (TestsTable test in tests) { if (patient.TestID == test.TestID) { final += " " + test.TestResults + " " + test.TestDate; } } final += "\nMedications:"; foreach (MedicationListTable med in meds) { if (patient.MedicationID == med.MedicationID) { final += " " + med.Description; } } final += "\nAppointments:"; foreach (AppointmentsTable app in appointments) { if (patient.PatientID == app.PatientID) { final += " " + app.VisitSummary + " " + app.Date + "\n"; } } return(final); }