protected void ShowPageInfo(HTTP_PAGEDB db) { //Our flag to know if the data can be shown or not bool valid = true; //Get the http_pageID from the query string http_pageID = Request.QueryString["http_pageID"]; //if there is no id then user must have went to this page without a id if (String.IsNullOrEmpty(http_pageID)) { valid = false; } //if there is a id on the page then if (valid) { //Get the HTTP_Page from the id we got HTTP_Page pageRecord = db.FindPage(Int32.Parse(http_pageID)); //Show the data on the HTML pageID.InnerHtml = pageRecord.GetID(); pageTitle.Text = pageRecord.GetTitle(); pageContent.Text = pageRecord.GetContent(); pageDatePublished.InnerHtml = pageRecord.GetDate().ToString("MM/dd/yyyy"); } //No id was found if (!valid) { http_page.InnerHtml = "There was an error finding that page."; } }
//This code is referenced from SCHOOLDB.cs in our examples public void AddPage(HTTP_Page newPage) { //Our query string string query = "insert into http_pages (HTTPPAGETITLE, HTTPPAGECONTENT, HTTPPAGEDATE) values ('{0}','{1}','{2}')"; query = String.Format(query, newPage.GetTitle(), newPage.GetContent(), newPage.GetDate().ToString("yyyy/MM/dd")); //Set up SQL Connection MySqlConnection Connect = new MySqlConnection(ConnectionString); //Give the connection a query MySqlCommand cmd = new MySqlCommand(query, Connect); //Try to add a page with the information provided to us. try { //Open the database connection Connect.Open(); //Run our query command on the database cmd.ExecuteNonQuery(); //Debug purpose Debug.WriteLine("Executed query " + query); } //An exception occured catch (Exception ex) { Debug.WriteLine("Something went wrong in the AddPage Method!"); Debug.WriteLine(ex.ToString()); } //Close our database connection Connect.Close(); }