protected void Update_Page(object sender, EventArgs e) { Pagedb db = new Pagedb(); bool valid = true; string pageid = Request.QueryString["pageid"]; if (String.IsNullOrEmpty(pageid)) { valid = false; } if (valid) { HTTP_Page new_page = new HTTP_Page(); //update the page new_page.SetPagetitle(edit_pagetitle.Text); new_page.SetPagebody(edit_pagebody.Text); //adding to the database try { db.Update_Page(Int32.Parse(pageid), new_page); Response.Redirect("~/ShowPage.aspx?pageid=" + pageid); } catch { valid = false; } } if (!valid) { editpage.InnerHtml = "There was an error updating that article."; } }
//Finding a particular page in the Daily Bugle Newspaper public HTTP_Page FindPage(int id) { MySqlConnection Connect = new MySqlConnection(ConnectionString); HTTP_Page result_page = new HTTP_Page(); try { string query = "select * from PAGES where pageid = " + id; Debug.WriteLine("Connection Initialized..."); Connect.Open(); MySqlCommand cmd = new MySqlCommand(query, Connect); MySqlDataReader resultset = cmd.ExecuteReader(); List <HTTP_Page> pages = new List <HTTP_Page>(); while (resultset.Read()) { HTTP_Page currentpage = new HTTP_Page(); for (int i = 0; i < resultset.FieldCount; i++) { string key = resultset.GetName(i); string value = resultset.GetString(i); Debug.WriteLine("Attempting to transfer " + key + " data of " + value); switch (key) { case "pagetitle": currentpage.SetPagetitle(value); break; case "pagebody": currentpage.SetPagebody(value); break; } } pages.Add(currentpage); } result_page = pages[0]; } catch (Exception ex) { Debug.WriteLine("Something went wrong in the find Page method!"); Debug.WriteLine(ex.ToString()); } Connect.Close(); Debug.WriteLine("Database Connection Terminated."); return(result_page); }
protected void Add_Page(object sender, EventArgs e) { //create connection Pagedb db = new Pagedb(); //create a new particular page HTTP_Page new_page = new HTTP_Page(); //detail about the page new_page.SetPagetitle(add_pagetitle.Text); new_page.SetPagebody(add_pagebody.Text); new_page.SetAuthorid(Int32.Parse(add_authorid.Text)); //add the page to the database db.Add_Page(new_page); Response.Redirect("List_Pages.aspx"); //Problem: When adding authorid in, the new page can not be added to the database, there is sth wrong in the List-Query method //Reason: 1. the authorid is added to the insert statement (solved) 2. the authorid is not convert from string into int //Status: solved }