Esempio n. 1
0
        public void UpdateGridView()
        {
            SqlConnection  conn = new SqlConnection(@"data source = .\sqlexpress; integrated security = true; database = Patient_dentist;");
            SqlDataAdapter da   = null;
            DataSet        ds   = null; //collection of tables (Used instead of a datareader)
            DataTable      dt   = null; // data tables inside the data set

            string sqlsel = "SELECT * from Reservation";

            try
            {
                //conn.Open(); SqlDataAdapter opens the connection itself

                da = new SqlDataAdapter(); // the new makes a new object
                da.SelectCommand = new SqlCommand(sqlsel, conn);

                ds = new DataSet();
                da.Fill(ds, "MyReservations");    // fills the dataset

                dt = ds.Tables["MyReservations"]; // we take the information from the dataset and inputs in the table

                GridViewReservations.DataSource = dt;
                GridViewReservations.DataBind();

                DropDownListPatient.DataSource     = dt;
                DropDownListPatient.DataTextField  = "ID_patient";
                DropDownListPatient.DataValueField = "ID_patient";
                DropDownListPatient.DataBind();
                DropDownListPatient.Items.Insert(0, "Select a patient");

                DropDownDate.DataSource     = dt;
                DropDownDate.DataTextField  = "Date";
                DropDownDate.DataValueField = "Date";
                DropDownDate.DataBind();
                DropDownDate.Items.Insert(0, "Select a date");
            }
            catch (Exception ex)
            {
                LabelMessage.Text = ex.Message;
            }
            finally
            {
                conn.Close(); //The SqlDataAdaptor closes connection by itself; but if something goes wrong, the DataAdaptor can not close the connection
            }
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            System.Data.DataTable datedrop = new System.Data.DataTable();
            datedrop.Columns.Add(new System.Data.DataColumn("Dates"));
            datedrop.Rows.Add(System.DateTime.Today.ToShortDateString());

            for (int i = -7; i < 7; i++)
            {
                datedrop.Rows.Add(System.DateTime.Today.AddDays(i).ToShortDateString());
            }

            DropDownDate.DataSource    = datedrop;
            DropDownDate.DataTextField = datedrop.Columns["Dates"].ToString();
            DropDownDate.DataBind();

            string          connetionString = null;
            MySqlConnection con;
            connetionString = "server=localhost;database=mydb;Uid=root;Pwd=;";
            con             = new MySqlConnection(connetionString);
        }
    }
Esempio n. 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            System.Data.DataTable datedrop = new System.Data.DataTable();
            datedrop.Columns.Add(new System.Data.DataColumn("Dates"));
            datedrop.Rows.Add(System.DateTime.Today.ToShortDateString());

            for (int i = -7; i < 7; i++)
            {
                datedrop.Rows.Add(System.DateTime.Today.AddDays(i).ToShortDateString());
            }

            DropDownDate.DataSource    = datedrop;
            DropDownDate.DataTextField = datedrop.Columns["Dates"].ToString();
            DropDownDate.DataBind();

            string          connetionString = null;
            MySqlConnection con;
            connetionString = "server=localhost;database=coffeedb;Uid=root;Pwd=;";
            con             = new MySqlConnection(connetionString);


            con.Open();
            MySqlCommand    sda = new MySqlCommand("SELECT sandwich FROM products", con);
            MySqlDataReader dr;
            dr = sda.ExecuteReader();
            dropdownSandwich.Items.Clear();
            while (dr.Read())
            {
                dropdownSandwich.Items.Add(new ListItem(dr[0].ToString(), dr[0].ToString()));
            }
            dropdownSandwich.DataBind();
            con.Close();

            con.Open();
            sda = new MySqlCommand("SELECT burger FROM products", con);
            dr  = sda.ExecuteReader();
            dropdownBurger.Items.Clear();
            while (dr.Read())
            {
                dropdownBurger.Items.Add(new ListItem(dr[0].ToString(), dr[0].ToString()));
            }
            dropdownBurger.DataBind();
            con.Close();

            con.Open();
            sda = new MySqlCommand("SELECT salad FROM products", con);
            dr  = sda.ExecuteReader();
            dropdownSalad.Items.Clear();
            while (dr.Read())
            {
                dropdownSalad.Items.Add(new ListItem(dr[0].ToString(), dr[0].ToString()));
            }
            dropdownSalad.DataBind();
            con.Close();

            con.Open();
            sda = new MySqlCommand("SELECT drink FROM products", con);
            dr  = sda.ExecuteReader();
            dropdownCoffee.Items.Clear();
            while (dr.Read())
            {
                dropdownCoffee.Items.Add(new ListItem(dr[0].ToString(), dr[0].ToString()));
            }
            dropdownCoffee.DataBind();
            con.Close();

            con.Open();
            sda = new MySqlCommand("SELECT dessert FROM products", con);
            dr  = sda.ExecuteReader();
            dropdownDessert.Items.Clear();
            while (dr.Read())
            {
                dropdownDessert.Items.Add(new ListItem(dr[0].ToString(), dr[0].ToString()));
            }
            dropdownDessert.DataBind();
            con.Close();
        }
    }