Exemple #1
0
        public void UpdateGridview()
        {
            SqlDataAdapter da = null;
            DataSet        ds = null;
            DataTable      dt = null;

            string sqlsel = "select * from treatments";

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

                da = new SqlDataAdapter();
                da.SelectCommand = new SqlCommand(sqlsel, conn);

                ds = new DataSet();

                da.Fill(ds, "MyTreatments");

                /*
                 * dt.Columns.Add("SponsorID", typeof(Int32));
                 * dt.Columns.Add("Name", typeof(string));
                 * dt.Columns.Add("Website", typeof(string));
                 * dt.Columns.Add("Picture", typeof(string));*/
                dt = ds.Tables["MyTreatments"];



                /*
                 * ds = new DataSet("Sponsors");
                 * dt = ds.Tables.Add("Sponsor");
                 *
                 * dt.Columns.Add("SponsorID", typeof(Int32));
                 * dt.Columns.Add("Name", typeof(string));
                 * dt.Columns.Add("Website", typeof(string));
                 * dt.Columns.Add("Picture", typeof(string));
                 * }
                 */
                TreatmentRepeater.DataSource = dt;


                TreatmentRepeater.DataBind();

                DropDownListTreatments.DataSource     = dt;
                DropDownListTreatments.DataTextField  = "T_Name";
                DropDownListTreatments.DataValueField = "T_Id";
                DropDownListTreatments.DataBind();
                DropDownListTreatments.Items.Insert(0, "Select a Treatment");
            }
            catch (Exception ex)
            {
                LabelMessage.Text = ex.Message;
            }
            finally
            {
                conn.Close();   // SqlDataAdapter closes connextion by itself; but can fail in case of errors
            }
        }
        public void UpdateGridview()
        {
            SqlConnection  conn = new SqlConnection(@"data source = .\sqlexpress; integrated security = true; database = 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 treatments";

            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, "MyTreatments");    // fills the dataset

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

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

                DropDownListTreatments.DataSource     = dt;
                DropDownListTreatments.DataTextField  = "name";
                DropDownListTreatments.DataValueField = "treatmentID";
                DropDownListTreatments.DataBind();
                DropDownListTreatments.Items.Insert(0, "Select a treatment");
            }
            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
            }
        }
        public void UpdateList()
        {
            SqlConnection  conn   = new SqlConnection(@"data source = .\sqlexpress; integrated security = true; database = Dentist");
            SqlDataAdapter da     = null;
            DataSet        ds     = null;
            DataTable      dt     = null;
            string         sqlsel = "select * from treatments";

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

                da = new SqlDataAdapter();
                da.SelectCommand = new SqlCommand(sqlsel, conn);

                ds = new DataSet();
                da.Fill(ds, "MyTreatments");

                dt = ds.Tables["MyTreatments"];



                DropDownListTreatments.DataSource     = dt;
                DropDownListTreatments.DataTextField  = "T_Name";
                DropDownListTreatments.DataValueField = "T_Id";
                DropDownListTreatments.DataBind();
                DropDownListTreatments.Items.Insert(0, "Select a Treatment");
            }
            catch (Exception ex)
            {
                LabelMessage.Text = ex.Message + ex.StackTrace;
            }
            finally
            {
                conn.Close();   // SqlDataAdapter closes connextion by itself; but can fail in case of errors
            }
        }