Ejemplo n.º 1
0
        public static List <Student> GetAll()
        {
            List <Student> allStudents = new List <Student> {
            };
            MySqlConnection conn       = DB.Connection();

            conn.Open();
            MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM student;";
            MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                Student newStudent = new Student();
                newStudent.SetId(rdr.GetInt32(0));
                newStudent.SetName(rdr.GetString(1));
                newStudent.SetDate(rdr.GetDateTime(2));
                allStudents.Add(newStudent);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(allStudents);
        }
Ejemplo n.º 2
0
        public static Student Find(int check)
        {
            Student         ret  = new Student();
            MySqlConnection conn = DB.Connection();

            conn.Open();
            MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM student where id = " + check + ";";
            MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader;

            rdr.Read();
            if (rdr.IsDBNull(0) == false)
            {
                ret.SetId(rdr.GetInt32(0));
                ret.SetName(rdr.GetString(1));
                ret.SetDate(rdr.GetDateTime(2));
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(ret);
        }