コード例 #1
0
        //Get the initial Select Box list of DVD names
        protected void UISelectRepopulate()
        {
            SqlConnection conn;
            SqlCommand    comm;
            SqlDataReader reader;
            string        connectionString = ConfigurationManager.ConnectionStrings["DVDconnstring"].ConnectionString;

            conn = new SqlConnection(connectionString);
            comm = new SqlCommand("SELECT DVDID, DVDtitle FROM DVDtable", conn);
            try
            {
                conn.Open();
                reader = comm.ExecuteReader();
                DropDownListDVD.DataSource     = reader;
                DropDownListDVD.DataValueField = "DVDID";
                DropDownListDVD.DataTextField  = "DVDtitle";
                DropDownListDVD.DataBind();
                reader.Close();
                dbErrorLabel.Text += "Select a DVD from the list to edit. ";
                UIClearFields();
            }
            catch
            {
                dbErrorLabel.Text = "Error getting DVD list from database. Ensure SQL is properly connected";
            }
            finally
            {
                conn.Close();
            }
        }
コード例 #2
0
ファイル: EditDVD.aspx.cs プロジェクト: kennethrae/BC
        private void LoadDVDList()
        {
            SqlConnection conn;
            SqlCommand    comm;
            SqlDataReader reader;
            string        connectionString = ConfigurationManager.ConnectionStrings["DVDdbCS"].ConnectionString;

            conn = new SqlConnection(connectionString);
            comm = new SqlCommand("SELECT DVDID, DVDtitle FROM DVDtable ORDER BY DVDtitle", conn);
            try
            {
                conn.Open();
                reader = comm.ExecuteReader();
                DropDownListDVD.DataSource     = reader;
                DropDownListDVD.DataValueField = "DVDID";    // note the binding here so we can use the ID
                DropDownListDVD.DataTextField  = "DVDtitle"; // but display the user friendly name
                DropDownListDVD.DataBind();
                reader.Close();
            }
            catch
            {
                LabelErrorMessage.Text = "Error loading the list of DVDs! <br />";
            }
            finally
            {
                conn.Close();
            }
            ButtonUpdateDVD.Enabled = false;
            ButtonDeleteDVD.Enabled = false;

            LabelErrorMessage.Text = "";
            TextBoxDVDtitle.Text   = "";
            TextBoxDVDartist.Text  = "";
            TextBoxDVDrating.Text  = "";
            TextBoxDVDprice.Text   = "";
        }