Exemplo n.º 1
0
        //SELECT
        public void UpdateGridview()
        {
            SqlConnection conn = new SqlConnection(@"data source = .\sqlexpress; integrated security = true; database = Patient_dentist;");
            SqlCommand    cmd  = null;
            //data reader
            SqlDataReader rdr = null;

            try
            {
                conn.Open();

                cmd             = conn.CreateCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "MySelectAllRes";


                SqlParameter in1 = cmd.Parameters.Add("@ID_patient", SqlDbType.Int);
                in1.Direction = ParameterDirection.Input;
                in1.Value     = Convert.ToInt32(Session["id"].ToString());

                //ExecuteReader -> access results
                rdr = cmd.ExecuteReader();

                GridViewUpdateRes.DataSource = rdr;
                GridViewUpdateRes.DataBind(); //withought databind wont display anything
            }
            catch (Exception ex)
            {
                LabelMessageCRR.Text = ex.Message + ex.StackTrace;
            }
            finally
            {
                conn.Close();
            }
        }
Exemplo n.º 2
0
        public void UpdateGridview()
        {
            SqlConnection conn = new SqlConnection(@"data source = .\sqlexpress; integrated security = true; database = Patient_dentist;");
            SqlCommand    cmd  = null;
            SqlDataReader rdr  = null;

            try
            {
                conn.Open();

                cmd             = conn.CreateCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "MySelectRes";

                SqlParameter in1 = cmd.Parameters.Add("@ID_patient", SqlDbType.Int);
                in1.Direction = ParameterDirection.Input;
                in1.Value     = Convert.ToInt32(Session["id"].ToString());

                rdr = cmd.ExecuteReader();

                GridViewUpdateRes.DataSource = rdr;
                GridViewUpdateRes.DataBind();

                rdr.Close();
                rdr = cmd.ExecuteReader();

                DropDownListRes.DataSource     = rdr;
                DropDownListRes.DataTextField  = "ID_res";
                DropDownListRes.DataValueField = "ID_res";
                DropDownListRes.DataBind();
                DropDownListRes.Items.Insert(0, "Select a reservation ID");
            }
            catch (Exception ex)
            {
                LabelMessageCRR.Text = ex.Message;
            }
            finally
            {
                conn.Close();
            }
        }