protected void Update_Author(object sender, EventArgs e) { Pagedb db = new Pagedb(); bool valid = true; string authorid = Request.QueryString["authorid"]; if (String.IsNullOrEmpty(authorid)) { valid = false; } if (valid) { Authors new_author = new Authors(); //update author new_author.SetAuthorfname(edit_authorfname.Text); new_author.SetAuthorlname(edit_authorlname.Text); //adding to the database try { db.Update_Author(Int32.Parse(authorid), new_author); Response.Redirect("~/ShowAuthor.aspx?authorid=" + authorid); } catch { valid = false; } } if (!valid) { editauthor.InnerHtml = "There was an error updating that author."; } }
public Authors FindAuthor(int id) { MySqlConnection Connect = new MySqlConnection(ConnectionString); Authors result_author = new Authors(); try { string query = "select * from authors where authorid = " + id; Debug.WriteLine("Connection Initialized..."); Connect.Open(); MySqlCommand cmd = new MySqlCommand(query, Connect); MySqlDataReader resultset = cmd.ExecuteReader(); List <Authors> authors = new List <Authors>(); while (resultset.Read()) { Authors currentauthor = new Authors(); 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 "authorfname": currentauthor.SetAuthorfname(value); break; case "authorlname": currentauthor.SetAuthorlname(value); break; } } authors.Add(currentauthor); } result_author = authors[0]; } catch (Exception ex) { Debug.WriteLine("Something went wrong in the find Author method!"); Debug.WriteLine(ex.ToString()); } Connect.Close(); Debug.WriteLine("Database Connection Terminated."); return(result_author); }