private void MyInitForAdd() { CDT_TextBox.Text = DateTime.Now.ToString("yyyy-MM-dd"); using (SqlConnection conn = new DB().GetConnection()) { SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "select * from Catalogs order by Orders desc"; conn.Open(); SqlDataReader rd = cmd.ExecuteReader(); CatalogsDDL.DataSource = rd; CatalogsDDL.DataValueField = "ID"; CatalogsDDL.DataTextField = "Catalog"; CatalogsDDL.DataBind(); rd.Close(); cmd.CommandText = "select max(Orders)+1 as orders from Shows"; rd = cmd.ExecuteReader(); if (rd.Read()) { MaxOrders.Text = rd[0].ToString(); } rd.Close(); } }
private void MyInitForUpdate() { string CatalogID = ""; using (SqlConnection conn = new DB().GetConnection()) { SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "select * from Catalogs order by Orders desc"; conn.Open(); SqlDataReader rd = cmd.ExecuteReader(); CatalogsDDL.DataSource = rd; CatalogsDDL.DataValueField = "ID"; CatalogsDDL.DataTextField = "Catalog"; CatalogsDDL.DataBind(); rd.Close(); cmd.CommandText = "Select * from Shows where ID = " + IDLabel.Text; rd = cmd.ExecuteReader(); if (rd.Read()) { TitleTB.Text = rd["Title"].ToString(); CatalogID = rd["CatalogID"].ToString(); CDT_TextBox.Text = String.Format("{0:yyyy-MM-dd}", rd["CDT"]); Orders.Text = rd["Orders"].ToString(); AbsTextBox.Text = rd["Abs"].ToString(); CoverPhoto.ImageUrl = rd["CoverPhotoURL"].ToString(); RandomID.Text = rd["RandomID"].ToString(); } rd.Close(); } if (!String.IsNullOrEmpty(CatalogID) && CatalogsDDL.Items.FindByValue(CatalogID) != null) { CatalogsDDL.Items.FindByValue(CatalogID).Selected = true; } }