Ejemplo n.º 1
0
        public static List <string> execute(string first_name, string last_name, string connection)
        {
            List <string> result = new List <string>();
            //List<string> result = new List<string>();
            OdbcConnection db = new OdbcConnection();

            db.ConnectionString = "FIL=MS Access;DSN=" + connection;
            try
            {
                db.Open();
                //Select all patients with future appointments
                //SELECT PATIENTS.PatientID, PATIENTS.LastName, PATIENTS.FirstName, APPOINTMENTS."Time", APPOINTMENTS."Date" FROM PATIENTS, APPOINTMENTS WHERE PATIENTS.PatientID = APPOINTMENTS.PatientID AND(APPOINTMENTS."Date" > CURDATE()) ORDER BY APPOINTMENTS."Date" DESC
                OdbcCommand    query  = new OdbcCommand("SELECT PATIENTS.PatientID, PATIENTS.LastName, PATIENTS.FirstName, APPOINTMENTS.\"Time\", APPOINTMENTS.\"Date\" FROM PATIENTS, APPOINTMENTS WHERE PATIENTS.PatientID = APPOINTMENTS.PatientID AND(PATIENTS.FirstName = '" + first_name + "') AND(PATIENTS.LastName = '" + last_name + "')AND (APPOINTMENTS.\"Date\" > CURDATE()) ORDER BY APPOINTMENTS.\"Date\" DESC", db);
                OdbcDataReader reader = query.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        result.Add(reader.GetString(4) + " " + reader.GetTime(3).ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Couldn't connect to database, error: " + ex, "Connection Error", MessageBoxButtons.OK);
                return(result);
            }
            finally
            {
                db.Close();
            }
            return(result);
        }