コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["userName"] == null || !(Session["roleNumber"].ToString().Equals("1")))
            {
                Response.Redirect("NotAuthorizatedPage.aspx");
            }
            String myConnectionString;

            myConnectionString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
            MySqlConnection conn = new MySqlConnection(myConnectionString);

            conn.Open();
            string           queryElection = "SELECT CONCAT(ELECTION_INFO, \", \", ELECTION_STARTING_DATE, \", \", ELECTION_ENDING_DATE) AS ELECTION FROM ELECTION WHERE ELECTION_STARTING_DATE > SYSDATE() OR ELECTION_INFO='#' ORDER BY ELECTION_INFO;";
            MySqlCommand     cmd           = new MySqlCommand(queryElection, conn);
            MySqlDataAdapter da            = new MySqlDataAdapter {
                SelectCommand = cmd
            };
            DataSet ds = new DataSet();

            da.Fill(ds);
            if (!IsPostBack)
            {
                DropDownListElection.DataTextField = ds.Tables[0].Columns["ELECTION"].ToString();
                DropDownListElection.DataSource    = ds.Tables[0];
                DropDownListElection.DataBind();
                DropDownListElection.SelectedItem.Text = "";
            }
            conn.Close();
        }
コード例 #2
0
        private void checkElections()
        {
            String myConnectionString;

            myConnectionString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
            MySqlConnection conn = new MySqlConnection(myConnectionString);

            conn.Open();
            string           queryElection = "SELECT CONCAT(ELECTION_INFO, \", \", ELECTION_STARTING_DATE, \", \", ELECTION_ENDING_DATE) AS ELECTION FROM ELECTION WHERE ELECTION_STARTING_DATE > SYSDATE() AND ELECTION_INFO!='#' ORDER BY ELECTION_INFO;";
            MySqlCommand     cmd           = new MySqlCommand(queryElection, conn);
            MySqlDataAdapter da            = new MySqlDataAdapter {
                SelectCommand = cmd
            };
            DataSet ds = new DataSet();

            da.Fill(ds);
            DropDownListElection.DataTextField = ds.Tables[0].Columns["ELECTION"].ToString();
            DropDownListElection.DataSource    = ds.Tables[0];
            DropDownListElection.DataBind();

            DropDownListElection.Items.Insert(0, new ListItem("Please select an election to verify your vote", ""));
            DropDownListElection.SelectedIndex = 0;

            conn.Close();
        }