Ejemplo n.º 1
0
        private void lstStudent_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = lstStudent.SelectedIndex - 2;

            if (lstStudent.SelectedIndex == -1)
            {
                clearUserInput();
                return;
            }
            if (index < 0 || index >= mStudents.Count)
            {
                ShowMessage("Please select a valid student.");
                lstStudent.SelectedIndex = -1;
                return;
            }
            clsStudent temp = (clsStudent)mStudents[index];

            txtStudentID.Text = temp.UnivID.ToString();
            txtFirstName.Text = temp.FirstName;
            txtLastName.Text  = temp.LastName;
            txtSchool.Text    = temp.Street;
            txtCity.Text      = temp.City;
            txtState.Text     = temp.State;
            txtZip.Text       = temp.Zip.ToString();


            try
            {
                openDatabaseConnection();
                mDB.Open();
                string sql = "SELECT University.ID, UniversityName "
                             + "FROM StudentInfo, StudentUniversity, University "
                             + "WHERE StudentInfo.UnivID = StudentUniversity.StudentID "
                             + "AND University.ID = studentUniversity.UniversityID "
                             + "AND StudentInfo.UnivID = " + clsSQL.ToSql(temp.UnivID) + ";";
                OleDbCommand    cmd = new OleDbCommand(sql, mDB);
                OleDbDataReader rdr = cmd.ExecuteReader();
                rdr.Read();

                rdr.Close();
            }
            catch (Exception ex)
            {
                ShowMessage("There was an unexpected error: " + ex.Message);
            }
            finally
            {
                closeDatabaseConnection();
            }
        }
Ejemplo n.º 2
0
        private void LoadDBTable(string sql)
        {
            if (mUserFile == null)
            {
                ShowMessage("Please select a valid file.");
                return;
            }
            try
            {
                mStudents.Clear();
                openDatabaseConnection();
                mDB.Open();
                OleDbCommand    cmd = new OleDbCommand(sql, mDB);;
                OleDbDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read() == true)
                {
                    clsStudent tempRecord = new clsStudent(
                        (int)rdr["StudentID"],
                        (string)rdr["LastName"],
                        (string)rdr["FirstName"],
                        (string)rdr["School"],
                        (string)rdr["City"],
                        (string)rdr["State"],
                        (int)rdr["Zip"]);

                    mStudents.Add(tempRecord);
                }
                rdr.Close();
            }
            catch (Exception ex)
            {
                ShowMessage("There was an unexpected error: " + ex);
            }
            finally
            {
                closeDatabaseConnection();
            }
        }