private void collectMemberships() { //Query to get memberships table string membershipSelect = "SELECT MEMBERSHIP_ID, DURATION, COST, RESTRICTED, " + "DESCRIPTION, ACTIVE, EXP_DATE, EXP_TYPE, DAY_PASS FROM MEMBERSHIP_TYPE "; command = new SqlCommand(membershipSelect, connection); try { connection.Open(); SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection); //Reads the memberships and stores them while (reader.Read()) { Memberships tempMember = new Memberships(); tempMember.MembershipID = reader["MEMBERSHIP_ID"].ToString(); tempMember.Duration = reader["DURATION"].ToString(); tempMember.Cost = reader["COST"].ToString(); tempMember.Description = reader["DESCRIPTION"].ToString(); tempMember.Active = reader["ACTIVE"].ToString(); tempMember.Restricted = reader["RESTRICTED"].ToString(); tempMember.ExpirationType = reader["EXP_TYPE"].ToString(); tempMember.Daypass = reader["DAY_PASS"] is DBNull ? "N" : reader["DAY_PASS"].ToString(); tempMember.Expiration = reader["EXP_DATE"] is DBNull ? DateTime.Now : Convert.ToDateTime(reader["EXP_DATE"]); memberships.Add(tempMember); } loadMembers(); } catch (Exception ex) { MessageBox.Show("Error 1 Membership Display: \n" + ex); } finally { connection.Close(); } }
private void loadMembershipCombo() { string membSelect = "SELECT MEMBERSHIP_ID, DESCRIPTION " + "FROM MEMBERSHIP_TYPE"; command = new SqlCommand(membSelect, connection); //open the connection to the database try { connection.Open(); //create the SqlDataReader object using the command object SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection); //use loop to read data while (reader.Read()) { //create temp object and call constructor Memberships tempMemb = new Memberships(); //read the rows and save in tempMemb tempMemb.MembershipID = reader["MEMBERSHIP_ID"].ToString(); tempMemb.Description = reader["DESCRIPTION"].ToString(); //add tempMemb object to the list memberships.Add(tempMemb); } //close the database connection.Close(); //load the name in the combo box foreach (Memberships aMembership in memberships) { string membDesc = aMembership.Description; cboMembType.Items.Add(membDesc); } } catch (Exception ex) { MessageBox.Show("Error Loading Memberships: " + ex); } }